Files
2025-10-25 03:02:53 +03:00

5.0 KiB
Raw Permalink Blame History

[meta.reflection.extract]

21 Metaprogramming library [meta]

21.4 Reflection [meta.reflection]

21.4.12 Value extraction [meta.reflection.extract]

1

#

The extract function template may be used to extract a value out of a reflection when its type is known.

2

#

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

3

#

[Note 1:

T is a reference type.

— end note]

4

#

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.

5

#

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

6

#

Returns:

  • (6.1)

    If T is a pointer type, then a pointer value pointing to the function represented by r.

  • (6.2)

    Otherwise, a pointer-to-member value designating the non-static data member or function represented by r.

7

#

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

8

#

Let U be the type of the value or object that r represents.

9

#

Returns: static_cast([:R:]), where R is a constant expression of type info such that R == r is true.

10

#

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);

11

#

Let U be remove_cv_t.

12

#

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));}