名前空間
変種
操作

swap(std::move_only_function)

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

汎用ユーティリティ
関係演算子 (C++20で非推奨)
 
関数オブジェクト
関数の呼び出し
(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++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 にオーバーロードします。lhsrhs の状態を交換します。実質的に 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 オブジェクトのターゲットをスワップする
(public member function) [編集]
std::swap アルゴリズムを特殊化する
(関数テンプレート) [編集]
English 日本語 中文(简体) 中文(繁體)