- functional[meta header]
- std[meta namespace]
- copyable_function[meta class]
- function[meta id-type]
- cpp26[meta cpp]
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;
}- f(1)[link op_call.md]
1
- C++26
- Clang: ??
- GCC: ??
- ICC: ??
- Visual C++: ??