Namespaces
Variants

swap(std::move_only_function)

ja.cppreference.net より
 
 
ユーティリティライブラリ
言語サポート
型サポート(基本型、RTTI)
ライブラリ機能テストマクロ (C++20)
プログラムユーティリティ
可変引数関数
コルーチンサポート (C++20)
契約サポート (C++26)
三方比較
(C++20)
(C++20)(C++20)(C++20)    
(C++20)(C++20)(C++20)

汎用ユーティリティ
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)(C++20)(C++20)    
(C++20)
swap および型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
共通ボキャブラリ型
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)



 
関数オブジェクト
関数呼び出し
(C++17)(C++23)
恒等関数オブジェクト
(C++20)
透過的な演算子ラッパー
(C++14)
(C++14)
(C++14)
(C++14)  
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)

古いバインダとアダプタ
(C++17まで)
(C++17まで)
(C++17まで)
(C++17まで)
(C++17まで)(C++17まで)(C++17まで)(C++17まで)
(C++20まで)
(C++20まで)
(C++17まで)(C++17まで)
(C++17まで)(C++17まで)

(C++17まで)
(C++17まで)(C++17まで)(C++17まで)(C++17まで)
(C++20まで)
(C++20まで)
 
 
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 オブジェクトのターゲットを交換する
(公開メンバ関数)
std::swap アルゴリズムを特殊化する
(関数テンプレート)