21 Metaprogramming library [meta]

21.4 Reflection [meta.reflection]

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 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.
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}); / OK constexpr info r4 = reflect_constant(K{"ebab"}); / error: constituent pointer / points to string literal — end example]
template<class T> consteval info reflect_object(T& expr);
Throws: meta​::​exception if E 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);
Throws: meta​::​exception if F 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.

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant