Namespaces
Variants

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
< cpp | meta
 
 
 
Reflection library
 
Reflection types and queries
Type properties
Type property queries
 
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

  • Fn be the type or type alias represented by fn_type,
  • Result be the type or type alias represented by result_type, and
  • ARGS... be the pack of types or type aliases whose elements are represented by the corresponding elements of arg_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_type or any element of arg_types does not represent a type or type alias.
  • If Fn, Result or any type in the pack ARGS... 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

#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) [edit]
deduces the result type of invoking a callable object with a set of arguments
(function template) [edit]
checks if the callable object can be invoked (as if by std::invoke) with a tuple of arguments
(function) [edit]
(C++11)
obtains a reference to an object of the template type argument for use in an unevaluated context
(function template) [edit]
specifies that a callable type can be invoked with a given set of argument types
(concept) [edit]
checks if a type can be invoked (as if by std::invoke) with the given argument types
(class template) [edit]