Nuta
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować się zalogować lub zmienić katalog.
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować zmienić katalogi.
Te szablony określają, czy można wywołać typ z określonymi typami argumentów. is_invocable_r a is_nothrow_invocable_r także określić, czy wynik wywołania jest konwertowany na określony typ. is_nothrow_invocable oraz is_nothrow_invocable_r określić, czy wywołanie jest znane, aby nie zgłaszać wyjątków. Dodano w języku C++17.
Składnia
template <class Callable, class... Args>
struct is_invocable;
template <class Convertible, class Callable, class... Args>
struct is_invocable_r;
template <class Callable, class... Args>
struct is_nothrow_invocable;
template <class Convertible, class Callable, class... Args>
struct is_nothrow_invocable_r;
// Helper templates
template <class Callable, class... Args>
inline constexpr bool is_invocable_v =
std::is_invocable<Callable, Args...>::value;
template <class Convertible, class Callable, class... Args>
inline constexpr bool is_invocable_r_v =
std::is_invocable_r<Convertible, Callable, Args...>::value;
template <class Callable, class... Args>
inline constexpr bool is_nothrow_invocable_v =
std::is_nothrow_invocable<Callable, Args...>::value;
template <class Convertible, class Callable, class... Args>
inline constexpr bool is_nothrow_invocable_r_v =
std::is_nothrow_invocable_r<Convertible, Callable, Args...>::value;
Parametry
Nieopłacona
Wywoływany typ zapytania.
Args
Typy argumentów do wykonywania zapytań.
Kabriolet
Typ wynik wywołania musi być konwertowany na.
Uwagi
Predykat is_invocable typu ma wartość true, jeśli wywoływany typ Callable można wywołać przy użyciu argumentów Args w nieszacowanym kontekście.
Predykat is_invocable_r typu ma wartość true, jeśli wywoływany typ Callable można wywołać przy użyciu argumentów Args w nieszacowanym kontekście w celu wygenerowania typu wyniku konwertowanego na kabriolet.
Predykat is_nothrow_invocable typu ma wartość true, jeśli wywoływany typ Callable można wywołać przy użyciu argumentów Args w nieszacowanym kontekście i że takie wywołanie jest znane, aby nie zgłaszać wyjątku.
Predykat is_nothrow_invocable_r typu ma wartość true, jeśli wywoływany typ Callable może być wywoływany przy użyciu argumentów Args w nieszacowanym kontekście w celu wygenerowania typu wyniku konwertowanego na kabriolet i że takie wywołanie jest znane, aby nie zgłaszać wyjątku.
Każdy z typów Cabrio, Callable i typów w pakiecie parametrów Args musi być kompletnym typem, tablicą nieznanej granicy lub ewentualnie kwalifikowanym voidcv. W przeciwnym razie zachowanie predykatu jest niezdefiniowane.
Przykład
// std__type_traits__is_invocable.cpp
// compile using: cl /EHsc /std:c++17 std__type_traits__is_invocable.cpp
#include <type_traits>
auto test1(int) noexcept -> int (*)()
{
return nullptr;
}
auto test2(int) -> int (*)()
{
return nullptr;
}
int main()
{
static_assert( std::is_invocable<decltype(test1), short>::value );
static_assert( std::is_invocable_r<int(*)(), decltype(test1), int>::value );
static_assert( std::is_invocable_r<long(*)(), decltype(test1), int>::value ); // fails
static_assert( std::is_nothrow_invocable<decltype(test1), int>::value );
static_assert( std::is_nothrow_invocable<decltype(test2), int>::value ); // fails
static_assert( std::is_nothrow_invocable_r<int(*)(), decltype(test1), int>::value );
static_assert( std::is_nothrow_invocable_r<int(*)(), decltype(test2), int>::value ); // fails
}
Wymagania
Nagłówek:<type_traits>
Przestrzeń nazw: std