Namespaces
Variants

std::meta::extract

From cppreference.com
< cpp | meta
 
 
 
Reflection library
 
Reflection types and queries
Reflection queries
Reflection layout queries
Type properties
Type property queries
 
Defined in header <meta>
template<class T>
consteval T extract( std::meta::info r );
(since C++26)

Extracts the value of what r represents as a value of type T.

Let UT be std::remove_cv_t<T>. The result is determined as follows:

  • If T is a reference type:
  • If r represents an object, returns a reference to that object.
  • Otherwise, r must represent a variable, returns a reference to the object of the variable.
  • Otherwise, if r represents a non-static data member or a function:
  • If UT is a pointer type, returns a pointer to the function represented by r.
  • Otherwise, UT must be a pointer-to-member type, returns a pointer-to-member value designating the entity represented by r.
  • Otherwise:
  • returns static_cast<UT>([:R:]) where R is a constant expression equal to std::meta::constant_of(r).

The type T and the type of what r represents can differ only in limited ways. See the #Exceptions section for details.

Parameters

r - a reflection value

Return value

The value of what r represents, as described above.

Exceptions

Throws std::meta::exception unless:

  • If T is a reference type, all of the following conditions are met:
  • r represents a variable or object.
  • Let RT be the type of the entity represented by r. Values of type RT can be converted to T via only qualification conversion.
  • 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.
  • Otherwise, if r represents a non-static data member or a function:
  • If r represents a non-static data member with type X that is a direct member of a class C:
  • The member is not a bit-field, UT and X C::* are similar types, and std::is_convertible_v<X C::*, UT> is true.
  • If r represents an implicit object member function with type F that is a direct member of a class C:
  • Otherwise, r represents a non-member function, static member function, or explicit object member function of function type F:
  • Otherwise, all the following conditions are met:
  • The expression std::meta::constant_of(r) does not throw.
  • Let RT be the type of the entity represented by std::meta::constant_of(r), any of the following conditions is met:
  • RT is a pointer type, UT and RT are either similar or both function pointer types, and std::is_convertible_v<RT, UT> is true.
  • RT is not a pointer type, and the cv-unqualified types of UT and RT are the same.
  • RT is an array type, UT is a pointer type, std::remove_extent_t<RT>* and UT are similar types, and the value represented by std::meta::constant_of(r) is convertible to UT.
  • RT is a closure type, UT is a function pointer type, and the value represented by std::meta::constant_of(r) is convertible to UT.

Example

See also

Morty Proxy This is a proxified and sanitized view of the page, visit original site.