std::swap(std::any)
From cppreference.com
| ヘッダー <any> で定義 |
||
| void swap( any& lhs, any& rhs ) noexcept; |
(C++17以降) | |
std::swap アルゴリズムの std::any 用オーバーロード。 lhs.swap(rhs) を呼び出すことにより、2つのanyオブジェクトの内容を交換します。
[編集] パラメータ
| 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 オブジェクトを交換する(public member function) |