swap(std::move_only_function)
ja.cppreference.net より
friend void swap( std::move_only_function& lhs, std::move_only_function& rhs ) noexcept;
|
(C++23以降) | |
std::swapアルゴリズムをstd::move_only_functionに対してオーバーロードします。lhsの状態をrhsの状態と交換します。効果的にlhs.swap(rhs)を呼び出します。
この関数は、通常の非修飾または修飾付き名前探索では可視ではなく、引数依存の名前探索によってのみ、std::move_only_function<FunctionType>が引数の関連クラスである場合に発見できます。
パラメータ
| lhs, rhs | - |
std::move_only_function
オブジェクトの状態を交換する
|
戻り値
(なし)
例
このコードを実行
#include <concepts> #include <functional> #include <iostream> void foo(const char* str, int x) { std::cout << "foo(\"" << str << "\", " << x << ")\n"; } void bar(const char* str, int x) { std::cout << "bar(\"" << str << "\", " << x << ")\n"; } int main() { std::move_only_function<void(const char*, int) const> f1{foo}; std::move_only_function<void(const char*, int) const> f2{bar}; f1("f1", 1); f2("f2", 2); std::cout << "std::ranges::swap(f1, f2);\n"; std::ranges::swap(f1, f2); // finds the hidden friend f1("f1", 1); f2("f2", 2); }
出力:
foo("f1", 1)
bar("f2", 2)
std::ranges::swap(f1, f2);
bar("f1", 1)
foo("f2", 2)
関連項目
2つの
std::move_only_function
オブジェクトのターゲットを交換する
(公開メンバ関数) |
|
|
(C++11)
|
std::swap
アルゴリズムを特殊化する
(関数テンプレート) |