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

履歴 編集

function template
<functional>

std::move_only_function::swap (非メンバ関数)(C++23)

friend void swap(move_only_function& f1, move_only_function& f2) noexcept;

概要

2つのmove_only_functionオブジェクトを入れ替える。

効果

f1.swap(f2)

戻り値

なし

#include <iostream>
#include <functional>

int ident(int x) { return x; }
int add(int x) { return x + 1; }

int main()
{
  std::move_only_function<int(int)> f = ident;
  std::move_only_function<int(int)> g = add;

  // fとgを交換
  std::swap(f, g);

  std::cout << f(1) << std::endl; // add
  std::cout << g(1) << std::endl; // ident
}

出力

2
1

バージョン

言語

  • C++23

処理系

参照