std::copyable_function::operator=
From cppreference.com
< cpp | utility | functional | copyable function
| copyable_function& operator=( const copyable_function& other ); |
(1) | (C++26以降) |
| copyable_function& operator=( copyable_function&& other ); |
(2) | (C++26以降) |
| copyable_function& operator=( std::nullptr_t ) noexcept; |
(3) | (C++26以降) |
| template< class F > copyable_function& operator=( F&& f ); |
(4) | (C++26以降) |
std::copyable_function に新しいターゲットを代入するか、そのターゲットを破棄します。
1)
other のターゲットのコピーを `*this` に代入します。これは `auto(other).swap(*this);` を実行するのと同等です。2) `other` が空の場合、 `other` のターゲットを `*this` に移動するか、または `*this` のターゲット(存在する場合)を破棄します。これは `auto(std::move(other)).swap(*this);` によって行われます。ムーブ代入後、`other` は有効な状態であり、値は未規定です。
3) 現在のターゲットが存在する場合、それを破棄します。呼び出し後、`*this` は空になります。
4) `*this` のターゲットを呼び出し可能なオブジェクト `f` に設定します。ただし、`f` がヌル関数ポインタ、ヌルメンバ関数ポインタ、または空の `std::copyable_function` の場合は、現在のターゲットを破棄します。これは `copyable_function(std::forward(f)).swap(*this);` を実行するのと同等です。このオーバーロードは、`F` からの `copyable_function` のコンストラクタがオーバーロード解決に参加する場合にのみ、オーバーロード解決に参加します。選択されたコンストラクタ呼び出しが無効または未定義の動作を引き起こす場合、プログラムは無効になるか、未定義の動作を持ちます。
目次 |
[編集] パラメータ
| その他 | - | ターゲットをコピーまたは移動する別の `std::copyable_function` オブジェクト |
| f | - | 新しいターゲットを初期化する呼び出し可能なオブジェクト |
[編集] 戻り値
*this
[編集] 例
| このセクションは未完成です 理由: 例がありません |
[編集] 関連項目
| 新しいターゲットを代入する ( std::function<R(Args...)> の public メンバ関数) | |
| ターゲットを置き換えるか破棄する ( std::move_only_function の public メンバ関数) |