GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::move_only_function::swap (非メンバ関数) - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. functional
  3. move_only_function
  4. swap (非メンバ関数)

最終更新日時: 2026年09月11日 13時06分31秒 (JST)
Akira Takahashi が更新

履歴 編集

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>
#include <utility>

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

処理系

  • Clang: ??
  • GCC: ??
  • Visual C++: ??

参照

  • P0288R9 move_only_function
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.