std::is_applicable, std::is_nothrow_applicable
| Defined in header <type_traits>
|
||
template< class Fn, class Tuple >
struct is_applicable;
|
(1) | (since C++26) |
template< class Fn, class Tuple >
struct is_nothrow_applicable;
|
(2) | (since C++26) |
Checks if the type Fn can be invoked (as if by std::invoke) with the given tuple Tuple of arguments.
Let /*ELEMS-OF*/(T) be the parameter pack std::get<N>(std::declval<T>()), where N is the pack of std::size_t template arguments of the specialization of std::index_sequence denoted by std::make_index_sequence<std::tuple_size_v<std::remove_reference_t<T>>>.
<Tuple> is true and INVOKE(std::declval<Fn>(), /*ELEMS-OF*/(Tuple)...) is well-formed when treated as an unevaluated operand.std::is_applicable_v<Fn, Tuple> is true and INVOKE(std::declval<Fn>(), /*ELEMS-OF*/(Tuple)...) is known not to throw any exceptions.If Fn or Tuple is not a complete type, (possibly cv-qualified) void, or an array of unknown bound, the behavior is undefined.
If an instantiation of a template above depends, directly or indirectly, on an incomplete type, and that instantiation could yield a different result if that type were hypothetically completed, the behavior is undefined.
If the program adds specializations for any of the templates described on this page, the behavior is undefined.
Helper variable templates
| Defined in header <type_traits>
|
||
template< class Fn, class Tuple >
constexpr bool is_applicable_v = is_applicable<Fn, Tuple>::value;
|
(1) | (since C++26) |
template< class Fn, class Tuple >
constexpr bool is_nothrow_applicable_v = is_nothrow_applicable<Fn, Tuple>::value;
|
(2) | (since C++26) |
Inherited from std::integral_constant
Member constants
value [static] |
true if (for overload (1)) INVOKE(std::declval<Fn>(), /*ELEMS-OF*/(Tuple)...) is well formed when treated as an unevaluated operand, false otherwise (public static member constant) |
Member functions
operator bool |
converts the object to bool, returns value (public member function) |
operator() (C++14) |
returns value (public member function) |
Member types
| Type | Definition |
value_type
|
bool
|
type
|
std::integral_constant<bool, value>
|
Notes
| Feature-test macro | Value | Std | Feature |
|---|---|---|---|
__cpp_lib_reflection |
202506L |
(C++26) | <meta>: Reflection library support. |
Examples
#include <tuple>
#include <type_traits>
#include <utility>
void func(char) noexcept;
static_assert(
std::is_applicable_v<int(), std::tuple<>> and
not std::is_applicable_v<int(), std::tuple<int>> and
std::is_applicable_v<std::declval(func), std::tuple<char>> and
not std::is_applicable_v<std::declval(func), std::tuple<char, int>> and
std::is_nothrow_applicable_v<std::declval(func), std::tuple<char>>
);
int main() {}
See also
(C++17) |
calls a function with a tuple of arguments (function template) |
(C++17)(C++23) |
invokes any Callable object with given arguments and possibility to specify return type(since C++23) (function template) |
(C++11)(removed in C++20)(C++17) |
deduces the result type of invoking a callable object with a set of arguments (class template) |
(C++11) |
obtains a reference to an object of the template type argument for use in an unevaluated context (function template) |
(C++20)(C++20) |
specifies that a callable type can be invoked with a given set of argument types (concept) |
(C++17)(C++17)(C++17)(C++17) |
checks if a type can be invoked (as if by std::invoke) with the given argument types (class template) |
(C++26)(C++26)(C++26)(C++26) |
checks if the reflected type can be invoked (as if by std::invoke) with the given argument types (function template) |
(C++26)(C++26) |
checks if a reflected type can be invoked (as if by std::invoke) with the given reflected tuple of arguments (function) |