std:: swap (std::any)
From cppreference.net
C++
Utilities library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
헤더 파일에 정의됨
<any>
|
||
|
void
swap
(
any
&
lhs, any
&
rhs
)
noexcept
;
|
(C++17 이후) | |
std::swap
알고리즘을
std::any
에 대해 오버로드합니다.
any
객체 두 개의 내용을
lhs.
swap
(
rhs
)
호출을 통해 교환합니다.
매개변수
| lhs, rhs | - | 교환할 객체 |
예제
이 코드 실행
#include <any> #include <print> #include <string> int main() { std::any p = 42, q = std::string{"Bishop"}; std::println("p: {}, q: {}", std::any_cast<int>(p), std::any_cast<std::string&>(q)); std::println("swap(p, q)"); std::swap(p, q); std::println("p: {}, q: {}", std::any_cast<std::string&>(p), std::any_cast<int>(q)); }
출력:
p: 42, q: Bishop swap(p, q) p: Bishop, q: 42
참고 항목
두 개의
any
객체를 교환
(public member function) |