template <class F, class Alloc>
void assign(F&& f, const Alloc& alloc);
この機能は、C++17で削除された。このクラスでメモリアロケータを使用する必要はない。
概要
関数オブジェクトとアロケータを再代入する。
効果
function(allocator_arg, alloc, std::forward<F>(f)).swap(*this)
戻り値
なし
例
#include <iostream>
#include <functional>
int ident(int x) { return x; }
int main()
{
std::function<int(int)> f;
// 関数とアロケータを代入。
//
// ※ここではint型を対象とするアロケータを渡しているが、
// 内部で適切な関数の型にrebindして使われる。
f.assign(ident, std::allocator<int>());
int result = f(1);
std::cout << result << std::endl;
}
出力
1
バージョン
言語
- C++11
処理系
- Clang: 3.0 ✅
- GCC: 4.8.2 ❌
- Visual C++: ??
参照
- N2308 Adding allocator support to
std::functionfor C++0x - P0302R1 Removing Allocator Support in
std::function(rev 1) - LWG Issue 1288.
std::functionassignment from rvalues- C++11で、関数オブジェクトを右辺値参照で受け取り、完全転送するようになった。ムーブのみ可能な引数を渡せるようにするため
- LWG Issue 2385.
function::assignallocator argument doesn't make sense