namespace std {
template <class R, class F, class... ArgsTypes>
struct is_invocable_r;
template <class R, class F, class... ArgsTypes>
inline constexpr bool is_invocable_r_v = std::is_invocable_r<R, F, ArgsTypes...>::value;
}
概要
型F
が、与えられた型の引数ArgsTypes...
で関数呼び出し可能であり、その戻り値型がR
に変換可能かどうかを調べる。
要件
型R, F
およびArgsTypes...
パラメータパックの全ての型が、完全型であること。もしくはconst
/volatile
修飾された(あるいはされていない)void
か、要素数不明の配列型であること。
効果
型F
に対して引数ArgsTypes...
によるINVOKE要件に従った呼び出しが可能であり、その結果となる戻り値の型がR
に変換可能であればtrue_type
から派生し、そうでなければfalse_type
から派生する。
結果は以下と等価である:
std::is_convertible_v<std::invoke_result_t<F, ArgsTypes...>, R>
例
#include <type_traits>
#include <iostream>
auto f(int) -> double {
return 0.0;
}
int main()
{
std::cout << std::boolalpha;
//f(int) -> double
std::cout << std::is_invocable_r<double, decltype(f), int>::value << std::endl;
//f(int) -> double -> int
std::cout << std::is_invocable_r<int, decltype(f), int>::value << std::endl;
//f(int*) (定義なし)
std::cout << std::is_invocable_r<double, decltype(f), int*>::value << std::endl;
//f(int) -> double -> char* (戻り値型変換不可)
std::cout << std::is_invocable_r<char*, decltype(f), int>::value << std::endl;
}
出力
true
true
false
false
バージョン
言語
- C++17
処理系
- Clang: ??
- GCC: ??
- Visual C++: 2017 Update 3