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<T> 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<V>)[0].
[Note 1: 
This is a reflection of an object for class types, and a reflection of a value otherwise.
— end note]
[Example 1: template<auto D> struct 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}); // OK constexpr info r4 = reflect_constant(K{"ebab"}); // error: constituent pointer // points to string literal — end example]
Throws: meta​::​exception unless the template-id TCls<V> would be valid given the invented variable template<T P> struct TCls;
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 unless expr 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& expr);
Mandates: T is a function type.
Returns: A reflection of the function designated by fn.
Throws: meta​::​exception unless expr is suitable for use as a constant template argument for a constant template parameter of type T& ([temp.arg.nontype]).