3.8 KiB
[meta.reflection.result]
21 Metaprogramming library [meta]
21.4 Reflection [meta.reflection]
21.4.14 Expression result reflection [meta.reflection.result]
template<class T> consteval info reflect_constant(T expr);
Mandates: is_copy_constructible_v is true and T is a cv-unqualified structural type ([temp.param]) that is not a reference type.
Let V be:
if T is a class type, then an object that is template-argument-equivalent to the value of expr;
otherwise, the value of expr.
Returns: template_arguments_of(^^TCls)[0], with TCls as defined below.
[Note 1:
This is a reflection of an object for class types, and a reflection of a value otherwise.
â end note]
Throws: meta::exception unless the template-id TCls would be valid given the invented templatetemplate struct TCls;
[Example 1: templatestruct A { };
struct N { int x; };struct K { char const* p; };
constexpr info r1 = reflect_constant(42);static_assert(is_value(r1));static_assert(r1 == template_arguments_of(^^A<42>)[0]);
constexpr info r2 = reflect_constant(N{42});static_assert(is_object(r2));static_assert(r2 == template_arguments_of(^^A<N{42}>)[0]);
constexpr info r3 = reflect_constant(K{nullptr}); // OKconstexpr info r4 = reflect_constant(K{"ebab"}); // error: constituent pointer// points to string literal â end example]
template<class T> consteval info reflect_object(T& expr);
Mandates: T is an object type.
Returns: A reflection of the object designated by expr.
Throws: meta::exception unlessexpr is suitable for use as a constant template argument for a constant template parameter of type T& ([temp.arg.nontype]).
template<class T> consteval info reflect_function(T& fn);
Mandates: T is a function type.
Returns: A reflection of the function designated by fn.
Throws: meta::exception unlessfn is suitable for use as a constant template argument for a constant template parameter of type T& ([temp.arg.nontype]).