std::swap(std::any)
ja.cppreference.net より
| ヘッダ <any>
|
||
void swap( any& lhs, any& rhs ) noexcept;
|
(C++17以上) | |
std::swap アルゴリズムを std::any に対してオーバーロードします。2つの 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
関連項目
2つの
any
オブジェクトを交換する
(公開メンバ関数) |