Skip to content

Latest commit

 

History

History
67 lines (49 loc) · 1.16 KB

File metadata and controls

67 lines (49 loc) · 1.16 KB

swap (非メンバ関数)

  • functional[meta header]
  • std[meta namespace]
  • move_only_function[meta class]
  • function template[meta id-type]
  • cpp23[meta cpp]
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
}
  • std::swap[color ff0000]
  • f(1)[link op_call.md]
  • g(1)[link op_call.md]

出力

2
1

バージョン

言語

  • C++23

処理系

参照