| copy (1) | function& operator= (const function& rhs); |
|---|---|
| move (2) | function& operator= (function&& rhs); |
| target (3) | template <class Fn> function& operator= (Fn&& fn);template <class Fn> function& operator= (reference_wrapper<Fn> fn) noexcept; |
| clear (4) | function& operator= (nullptr_t fn); |
std::move(fn)).*this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// function::operator= example
#include <iostream> // std::cout
#include <functional> // std::function, std::negate
int main () {
std::function<int(int)> foo,bar;
foo = std::negate<int>(); // target
bar = foo; // copy
foo = std::function<int(int)>([](int x){return x+1;}); // move
bar = nullptr; // clear
std::cout << "foo: " << foo(100) << '\n';
return 0;
}
foo: 101