- functional[meta header]
- std[meta namespace]
- function[meta class]
- function[meta id-type]
- cpp11[meta cpp]
function& operator=(const function& f); // (1)
function& operator=(function&& f); // (2)
function& operator=(nullptr_t); // (3)
template<class F>
function& operator=(F&& f); // (4)
template<class F>
function& operator=(reference_wrapper<F> f) noexcept; // (5)
- (1) :
function
(f).
swap
(*this)
- (2) :
*this
が持つ関数を、f
のそれで置き換える。 - (3) :
*this
が有効な関数ポインタ、メンバポインタ、もしくは関数オブジェクトを持っている場合、それを解放する。 - (4) :
function
(
std::forward
<F>(f)).
swap
(*this)
- (5) :
function
(f).
swap
(*this)
*this
- (5) : 投げない
- (4) :
- C++14 :
typename
decay
<F>::type
型の関数オブジェクトが、パラメータとしてArgTypes...
型をとり、戻り値としてR
型を返さない場合、この関数はオーバーロード解決から除外される。
- C++14 :
#include <iostream>
#include <functional>
int ident(int x) { return x; }
int main()
{
std::function<int(int)> f;
// 関数を代入
f = ident;
int result = f(1);
std::cout << result << std::endl;
}
- f(1)[link op_call.md]
1
- C++11
- Clang: 3.0 [mark verified]
- GCC: 4.3.6 [mark verified]
- Visual C++: ??
- LWG Issue 2132.
std::function
ambiguity- C++14から、(4)でシグニチャが合わない関数オブジェクトが渡された場合に、SFINAEされるようになった。