[meta.reflection.result] (original) (raw)
21 Metaprogramming library [meta]
21.4.15 Expression result reflection [meta.reflection.result]
template<class T> consteval info reflect_constant(T expr);
Mandates: is_copy_constructible_v<T> is trueand 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.
Let TCls be the invented template:template<T P> struct TCls;
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_]
Throws: meta::exception unless the template-id TCls<V> would be valid.
[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}); constexpr info r4 = reflect_constant(K{"ebab"}); — _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 ifE is not suitable for use as a constant template argument for a constant template parameter of type T& ([temp.arg.nontype]), where E is an lvalue constant expression that computes the object that expr refers to.
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 ifF is not suitable for use as a constant template argument for a constant template parameter of type T& ([temp.arg.nontype]), where F is an lvalue constant expression that computes the function that fn refers to.