std::meta::invoke_result
From cppreference.com
| Defined in header <meta>
|
||
template< std::meta::reflection_range Args = std::initializer_list<std::meta::info> >
consteval std::meta::info invoke_result( std::meta::info func, Args&& args );
|
(since C++26) | |
Deduces the return type of an INVOKE expression.
Let Func denote the Callable represented by func and ARGS... denote the types or type aliases represented by successive elements of args.
Equivalent to return std::invoke_result_t<Func, ARGS...>;.
If Func cannot be called with the arguments ARGS... in unevaluated context, the program is ill-formed.
Template parameters
| Args | - | range type that contains invocation arguments' reflected types |
Parameters
| func | - | a reflection of the invocable object type |
| args | - | a range of reflections representing invocation arguments |
Return value
A reflection of the return type of the Callable type Func as if invoked with the arguments ARGS....
Exceptions
Throws std::meta::exception:
- If either
funcor any element ofargsdoes not represent a type or type alias. - If
funcor any element in theargsdoes not represent a complete type, (possibly cv-qualified)void, or an array of unknown bound. - If an instantiation of a template
invoke_resultdepends, 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 <initializer_list>
#include <meta>
void f();
int& g(int&, short);
static_assert(
(invoke_result(^^decltype(f), {}) == ^^void) and
(invoke_result(^^decltype(g), {^^int&, ^^short}) == ^^int&)
);
struct S
{
double operator()(char, int&);
float operator()(int) { return 1.0; }
};
static_assert(
(invoke_result(^^S, {^^char, ^^int&}) == ^^double) and
(invoke_result(^^S, {^^int}) == ^^float)
);
template <typename T>
struct R
{
const T& operator()(int, double);
};
static_assert(
(invoke_result(^^R<int>, {^^int, ^^double}) == ^^const int&) and
(invoke_result(^^R<int>, {^^char, ^^float}) == ^^const int&) and
"");
int main() {}
