• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function template
    <functional>

    std::copyable_function::swap (非メンバ関数)

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

    概要

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

    効果

    f1.swap(f2)

    戻り値

    なし

    #include <iostream>
    #include <functional>
    
    int ident(int x) { return x; }
    int add(int x) { return x + 1; }
    
    int main()
    {
      std::copyable_function<int(int)> f = ident;
      std::copyable_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++26

    処理系

    参照