std::meta::extract
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
Tis a reference type: - If
rrepresents an object, returns a reference to that object. - Otherwise,
rmust represent a variable, returns a reference to the object of the variable. - Otherwise, if
rrepresents a non-static data member or a function: - If
UTis a pointer type, returns a pointer to the function represented byr. - Otherwise,
UTmust be a pointer-to-member type, returns a pointer-to-member value designating the entity represented byr. - Otherwise:
- returns
static_cast<UT>([:R:])whereRis a constant expression equal tostd::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
Tis a reference type, all of the following conditions are met: -
rrepresents a variable or object. - Let
RTbe the type of the entity represented byr. Values of typeRTcan be converted toTvia only qualification conversion. - If
rrepresents 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
rrepresents a non-static data member or a function: - If
rrepresents a non-static data member with typeXthat is a direct member of a classC: - The member is not a bit-field,
UTandX C::*are similar types, andstd::is_convertible_v<X C::*, UT>istrue. - If
rrepresents an implicit object member function with typeFthat is a direct member of a classC: - Values of type
F C::*can be converted toUTvia only function pointer conversion. - Otherwise,
rrepresents a non-member function, static member function, or explicit object member function of function typeF: - Values of type
F*can be converted toUTvia only function pointer conversion. - Otherwise, all the following conditions are met:
- The expression
std::meta::constant_of(r)does not throw. - Let
RTbe the type of the entity represented bystd::meta::constant_of(r), any of the following conditions is met: -
RTis a pointer type,UTandRTare either similar or both function pointer types, andstd::is_convertible_v<RT, UT>istrue. -
RTis not a pointer type, and the cv-unqualified types ofUTandRTare the same. -
RTis an array type,UTis a pointer type,std::remove_extent_t<RT>*andUTare similar types, and the value represented bystd::meta::constant_of(r)is convertible toUT. -
RTis a closure type,UTis a function pointer type, and the value represented bystd::meta::constant_of(r)is convertible toUT.
Example
See also
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/meta/extract