copyable_function& operator=(const copyable_function& f); // (1)
copyable_function& operator=(copyable_function&& f); // (2)
copyable_function& operator=(nullptr_t); noexcept; // (3)
template<class F>
copyable_function& operator=(F&& f); // (4)
効果
- (1) : コピー代入。
copyable_function(f).swap(*this)
- (2) : ムーブ代入。
copyable_function(std::move(f)).swap(*this)
- (3) :
*this
が有効な関数ポインタ、メンバポインタ、もしくは関数オブジェクトを持っている場合、それを解放する。 - (4) :
copyable_function(std::forward<F>(f)).swap(*this)
戻り値
*this
例外
- (3) : 投げない
例
#include <iostream>
#include <functional>
int ident(int x) { return x; }
int main()
{
std::copyable_function<int(int)> f;
// 関数を代入
f = ident;
int result = f(1);
std::cout << result << std::endl;
}
出力
1
バージョン
言語
- C++26
処理系
- Clang: ??
- GCC: ??
- ICC: ??
- Visual C++: ??