最終更新日時(UTC):
が更新

履歴 編集

function template
<functional>

std::function::assign(C++11)(C++17で削除)

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

処理系

参照