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