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;
}
xxxxxxxxxx
#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++: ??