constexpr function_ref& operator=(const function_ref&) noexcept = default; // (1)
template<class T> function_ref& operator=(T) = delete; // (2)
概要
コピー代入演算子。
テンプレートパラメータ制約
- (2) : 以下の制約をみたすとき、代入演算子はdelete宣言される
Tがfunction_refと同一型ではなく、かつ- 説明専用の
is-convertible-from-specialization<T>(コンストラクタを参照)がfalseであり、かつ is_pointer_v<T>がfalseであり、かつTがconstant_arg_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
処理系
- Clang: ??
- GCC: ??
- ICC: ??
- Visual C++: ??
参照
- P0792R14
function_ref: a type-erased callable reference - P3774R1 Rename
std::nontype, and make it broadly useful - P3961R1 Less double indirection in
function_ref(RU-220)- delete宣言される代入演算子(2)の制約に、説明専用の
is-convertible-from-specializationの条件を追加した
- delete宣言される代入演算子(2)の制約に、説明専用の