• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <functional>

    std::function_ref::operator=

    constexpr function_ref& operator=(const function_ref&) noexcept = default; // (1)
    
    template<class T> function_ref& operator=(T) = delete; // (2)
    

    概要

    コピー代入演算子。

    テンプレートパラメータ制約

    • (2) : 以下の制約をみたすとき、代入演算子はdelete宣言される
      • Tfunction_refと同一型ではなく、かつ
      • is_pointer_v<T>falseであり、かつ
      • Tnontype_tの特殊化でないこと

    効果

    • (1) : コピー代入。

    戻り値

    *this

    #include <iostream>
    #include <functional>
    
    int ident(int x)
    { return x; }
    
    int twice(int x)
    { return x * 2; }
    
    int main()
    {
      std::function_ref<int(int)> f = ident;
      std::function_ref<int(int)> g = twice;
    
      // コピー代入
      f = g;
    
      std::cout << f(1) << std::endl;
    }
    

    出力

    2
    

    バージョン

    言語

    • C++26

    処理系

    参照