namespace std {
template<class F>
function_ref(F*) -> function_ref<F>; // (1)
template<auto f>
function_ref(nontype_t<f>) -> function_ref<see below>; // (2)
template<auto f, class T>
function_ref(nontype_t<f>, T&&) -> function_ref<see below>; // (3)
}
概要
std::function_ref
クラステンプレートの型推論補助。
テンプレートパラメータ制約
- (1) :
is_function<F>
がtrue
であること。 - (2) :
F
をremove_pointer_t<decltype(f)>
としたとき、is_function<F>
がtrue
であること。 - (3) :
F
をdecltype(f)
としたとき- 型
G
に対してF
がR(G::*)(A...) /*cv*/ & noexcept(E)
の形式(参照修飾子&
は省略可、E
はbool
値)、または - 型
G
とオブジェクト型M
に対してF
がM G::*
の形式、または - 型
G
に対してF
がR(*)(G, A...) noexcept(E)
の形式(E
はbool
値)であること
- 型
備考
- (2) :
F
をremove_pointer_t<decltype(f)>
としたとき、型function_ref<F>
に推論される。 - (3) : 型
function_ref<R(A...) noexcept(E)>
に推論される。F
がM G::*
の形式のとき、R
はinvoke_result_t<F, T&>
、A...
は空のパック、E
はfalse
とする。- それ以外の形式のときは、テンプレートパラメータ制約の説明を参照。
例
#include <functional>
int ident(int x) { return x; }
struct X {
int data;
int mf(int x) { return x; }
};
int fun(X& obj) { return obj.data; }
int main()
{
// (1) 関数ポインタ
std::function_ref f1{&ident};
// (2) 関数ポインタ/NTTP
std::function_ref f2{std::nontype<&ident>};
// (3a) メンバ関数+オブジェクト束縛
X obj{42};
std::function_ref f3a{std::nontype<&X::mf>, obj};
// (3b) メンバ変数+オブジェクト束縛
std::function_ref f3b{std::nontype<&X::data>, obj};
// (3c) 関数ポインタ+第1引数束縛
std::function_ref f3c{std::nontype<&fun>, obj};
}
28
std::function_ref f3b{std::nontype<&X::data>, obj};
#include <functional>
int ident(int x) { return x; }
struct X {
int data;
int mf(int x) { return x; }
};
int fun(X& obj) { return obj.data; }
int main()
{
// (1) 関数ポインタ
std::function_ref f1{&ident};
// (2) 関数ポインタ/NTTP
std::function_ref f2{std::nontype<&ident>};
出力
バージョン
言語
- C++26
処理系
- Clang: ??
- GCC: ??
- ICC: ??
- Visual C++: ??