21 Metaprogramming library [meta]

21.4 Reflection [meta.reflection]

21.4.11 Value extraction [meta.reflection.extract]

The extract function template may be used to extract a value out of a reflection when its type is known.
The following are defined for exposition only to aid in the specification of extract.
template<class T> consteval T extract-ref(info r); // exposition only
[Note 1: 
T is a reference type.
— end note]
Constant When:
  • r represents a variable or object of type U,
  • is_convertible_v<remove_reference_t<U>(*)[],​ remove_reference_t<​T>(*)[]> is true,
    and
    [Note 2: 
    The intent is to allow only qualification conversion from U to T.
    — end note]
  • If r represents a variable, then either that variable is usable in constant expressions or its lifetime began within the core constant expression currently under evaluation.
Returns: If r represents an object O, then a reference ot O.
Otherwise, a reference to the object declared, or referred to, by the variable represented by r.
template<class T> consteval T extract-member-or-function(info r); // exposition only
Constant When:
  • r represents a non-static data member with type X, that is not a bit-field, that is a direct member of class C, T and C are similar types ([conv.qual]), and T is is_convertible_v<​X C​::​*, T> is true;
  • r represents an implicit object member function with type F or F noexcept that is a direct member of a class C, and T is F C​::​*; or
  • r represents a non-member function, static member function, or explicit object member function of function type F or F noexcept, and T is F*.
Returns:
  • If T is a pointer type, then a pointer value pointing to the function represented by r.
  • Otherwise, a pointer-to-member value designating the non-static data member or function represented by r.
template<class T> consteval T extract-value(info r); // exposition only
Let U be the type of the value or object that r represents.
Constant When:
  • U is a pointer type, T and U are similar types ([conv.qual]), and is_convertible_v<​U, T> is true,
  • U is not a pointer type and the cv-unqualified types of T and U are the same,
  • U is an array type, T is a pointer type, and the value r represents is convertible to T, or
  • U is a closure type, T is a function pointer type, and the value that r represents is convertible to T.
Returns: static_cast<T>([:R:]), where R is a constant expression of type info such that R == r is true.
template<class T> consteval T extract(info r);
Let U be remove_cv_t<T>.
Effects: Equivalent to: if constexpr (is_reference_type(^^T)) { return extract-ref<T>(r); } else if constexpr (is_nonstatic_data_member(r) || is_function(r)) { return extract-member-or-function<U>(r); } else { return extract-value<U>(constant_of(r)); }