5.0 KiB
[meta.reflection.extract]
21 Metaprogramming library [meta]
21.4 Reflection [meta.reflection]
21.4.12 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]
Returns: If r represents an object O, then a reference to O.
Otherwise, a reference to the object declared, or referred to, by the variable represented by r.
Throws: meta::exception unless
r represents a variable or object of type U,
is_convertible_v<remove_reference_t()[], 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.
template<class T> consteval T extract-member-or-function(info r); // exposition only
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.
Throws: meta::exception unless
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 X C::* are similar types ([conv.qual]), and 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*.
template<class T> consteval T extract-value(info r); // exposition only
Let U be the type of the value or object that r represents.
Returns: static_cast([:R:]), where R is a constant expression of type info such that R == r is true.
Throws: meta::exception unless
U is a pointer type, T and U are either similar ([conv.qual]) or both function pointer types, 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.
template<class T> consteval T extract(info r);
Let U be remove_cv_t.
Effects: Equivalent to:if constexpr (is_reference_type(^^T)) {return extract-ref(r);} else if constexpr (is_nonstatic_data_member(r) || is_function(r)) {return extract-member-or-function(r);} else {return extract-value(constant_of(r));}