std::meta::is_invocable_type, std::meta::is_invocable_r_type, std::meta::is_nothrow_invocable_type, std::meta::is_nothrow_invocable_r_type
From cppreference.com
| Defined in header <meta>
|
||
template< std::meta::reflection_range Args = std::initializer_list<std::meta::info> >
consteval bool is_invocable_type( std::meta::info fn_type, Args&& arg_types );
|
(1) | (since C++26) |
template< std::meta::reflection_range Args = std::initializer_list<std::meta::info> >
consteval bool is_invocable_r_type( std::meta::info result_type,
std::meta::info fn_type,
Args&& arg_types );
|
(2) | (since C++26) |
template< std::meta::reflection_range Args = std::initializer_list<std::meta::info> >
consteval bool is_nothrow_invocable_type( std::meta::info fn_type, Args&& arg_types );
|
(3) | (since C++26) |
template< std::meta::reflection_range Args = std::initializer_list<std::meta::info> >
consteval bool is_nothrow_invocable_r_type( std::meta::info result_type,
std::meta::info fn_type,
Args&& arg_types );
|
(4) | (since C++26) |
Determines if the reflected type can be invoked (as if by std::invoke) with the given argument types.
Let
Fnbe the type or type alias represented byfn_type,Resultbe the type or type alias represented byresult_type, andARGS...be the pack of types or type aliases whose elements are represented by the corresponding elements ofarg_types.
1) Equivalent to
return std::is_invocable_v<Fn, ARGS...>;.2) Equivalent to
return std::is_invocable_r_v<Result, Fn, ARGS...>;.3) Equivalent to
return std::is_nothrow_invocable_v<Fn, ARGS...>;.4) Equivalent to
return std::is_nothrow_invocable_r_v<Result, Fn, ARGS...>;.Template parameters
| Args | - | an initializer list the elements of which represent the types of invocation arguments |
Parameters
| fn_type | - | reflected invocable object type |
| arg_types | - | reflected argument types of invocation |
| result_type | - | reflected result type of invocation |
Return value
true if reflected type fn_type can be invoked with the given argument types. Otherwise, false.
Exceptions
Throws std::meta::exception:
- If either
fn_type,result_typeor any element ofarg_typesdoes not represent a type or type alias. - If
Fn,Resultor any type in the packARGS...is not a complete type, (possibly cv-qualified)void, or an array of unknown bound. - If an instantiation of a template (1-4) depends, directly or indirectly, on an incomplete type, and that instantiation could yield a different result if that type were hypothetically completed.
Example
Run this code
#include <meta>
auto func(char) -> int(*)();
static_assert
(""
&& is_invocable_type(^^void(int, char), {^^int, ^^char})
&& !is_invocable_type(^^void(void), {^^int})
&& is_invocable_type(^^decltype(func), {^^char})
&& !is_invocable_type(^^decltype(int()), {^^int})
&& is_invocable_r_type(^^void, ^^void(int), {^^int})
&& !is_invocable_r_type(^^void, ^^void(int), {^^void})
&& is_invocable_r_type(^^int(*)(), ^^decltype(func), {^^char})
&& !is_invocable_r_type(^^int(*)(), ^^decltype(func), {^^void})
);
int main() {}
See also
(C++17)(C++23) |
invokes any Callable object with given arguments and possibility to specify return type(since C++23) (function template) |
(C++26) |
deduces the result type of invoking a callable object with a set of arguments (function template) |
(C++26)(C++26) |
checks if the callable object can be invoked (as if by std::invoke) with a tuple of arguments (function) |
(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) |