The C++ Extensions for Reflection, ISO/IEC TS 23619:2021, specifies modifications to the core language and defines new components for the C++ standard library listed on this page.
The Reflection TS is based on the C++20 standard (except that the definition of concepts are specified in the style of Concepts TS).
[edit] Core language changes [edit] reflexpr-specifierA reflexpr-specifier is of form reflexpr
(
reflexpr-operand )
, and specifies a meta-object type (see below).
reflexpr-operand can be one of following:
::
(1) type-id (2) nested-name-specifier(optional) namespace-name (3) id-expression (4) (
expression )
(5) function-call-expression (6) functional-type-conv-expression (7)
where function-call-expression is
postfix-expression(
expression-list(optional) )
and functional-type-conv-expression are following sorts of expressions which perform explict cast:
simple-type-specifier(
expression-list(optional) )
(1) typename-specifier (
expression-list(optional) )
(2) simple-type-specifier braced-init-list (3) typename-specifier braced-init-list (4)
The operand to the reflexpr-specifier shall be a type, namespace, enumerator, variable, data member, function parameter, captured entity, function-call-expression or functional-type-conv-expression, and parenthesized expression. reflexpr(::) reflects the global namespace.
For a reflexpr-operand of form (
expression )
, the expression shall be a (possibly multi-parenthesized) function-call-expression or functional-type-conv-expression.
If an unparenthesized operand can be treated as either a type-id or a functional-type-conv-expression, then it is treated as a type-id. Parenthesizes can be used for disambiguation between function-style cast and a type-id. For example, given a class type X
with default constructor, reflexpr(X()) reflects the function type X(), and reflexpr((X())) reflects the expression X().
If the operand designates both an alias and a class name, the type represented by the reflexpr-specifier reflects the alias and satisfies reflect::Alias
.
If the operand designates a name whose declaration is enclosed in a block scope and the named entity is neither captured nor a function parameter, the program is ill-formed.
[edit] Meta-object typesA meta-object type is an unnamed, incomplete namespace-scope class type. A type satisfies the concept reflect::Object
if and only if it is a meta-object type. Meta-object types may satisfy other concepts, depending on the operand to reflexpr
.
It is unspecified whether repeatedly applying reflexpr
to the same operand yields the same type or a different type. If a meta-object type reflects an incomplete class type, certain type transformations cannot be applied.
A meta-object type allows inspection of some properties of the operand to reflexpr
through type traits or type transformations on it.
If the postfix-expression of the function-call-expression is of class type, i.e. e in the function-call-expression e(args) is of class type, then the user-defined conversion function of the type of the postfix-expression (e) shall not be used.
If postfix-expression is not of class type, it shall name a function that is the unique result of overload resolution.
struct Functor { void operator()(int) const; using fptr_t = void(*)(std::nullptr_t); operator fptr_t() const; }; using Meta0 = reflexpr(Functor{}(0)); // OK // using Meta1 = reflexpr(Functor{}(nullptr)); // error: conversion function used[edit]
An alias is a name introduced by a typedef declaration, an alias-declaration, or a using-declaration.
An entity or alias B
is reflection-related to an entity or alias A
if
A
and B
are the same entity or alias,A
is a variable or enumerator and B
is the type of A
,A
is an enumeration and B
is the underlying type of A
,A
is a class and B
is a member or base class of A
,A
is a non-template alias that designates the entity B
,A
is not the global namespace and B
is an enclosing class or namespace of A
,A
is the parenthesized expression ( B
),A
is a lambda capture of the closure type B
,A
is the closure type of the lambda capture B
,B
is the type specified by the functional-type-conv-expression A
,B
is the function selected by overload resolution for a function-call-expression A
,B
is the return type, a parameter type, or function type of the function A
, orB
is reflection-related to an entity or alias X
and X
is reflection-related to A
.Reflection-relation relationship is reflexive and transitive, but not symmetric.
Informally speaking, the case that B
is reflection-related to A
means that B
participates in the declaration or definition of A
.
Zero or more successive applications of type transformations that yield meta-object types to the type denoted by a reflexpr-specifier enable inspection of entities and aliases that are reflection-related to the operand; such a meta-object type is said to reflect the respective reflection-related entity or alias.
struct X; struct B { using X = ::X; typedef X Y; }; struct D : B { using B::Y; }; // ::X, but not B::X or B::Y is reflection-related to D::Y[edit] Miscellaneous
reflexpr
operand is not considered to be an unevaluated operand.T
is odr-used by the specialization std::experimental::reflect::get_pointer<T>, as if by taking the address of an id-expression nominating the function or variable.__cpp_reflection
(reflection TS)
a value of at least 201902 indicates that the Reflection TS is supportedRecordMember
, Enumerator
, or Variable
, or reflects a namespace other than the global namespace
get_base_classes
Object
operations checks if two meta-object types reflect the same entity or alias
ObjectSequence
operations obtains the size of a meta-object sequence
Named
operations checks if the reflected entity or alias is unnamed
Alias
operations obtains the meta-object type reflecting the associated entity of the reflected alias
Type
operations obtains the meta-object type reflecting the type of the reflected entity or alias
ScopeMember
operations obtains the meta-object type reflecting the scope of the reflected entity or alias
Base
operations obtains the meta-object type reflecting the base class in the given base class relationship
RecordMember
and Base
operations checks if the reflected member or base class is public
Record
operations obtains a meta-object sequence type whose elements reflect public, accessible, or all data members of the reflected class
Enum
operations checks whether the reflected enumeration is scoped
Variable
operations obtains the value of the reflected variable which is a constant expression
FunctionParameter
operations checks whether the reflected parameter has a default argument
Callable
operations obtains a meta-object sequence type whose elements reflects the parameters of the reflected function
Variable
and Callable
operations checks if the reflected variable or function is constexpr
Namespace
and Callable
operations checks whether the reflected namespace or function is inline
ParenthesizedExpression
operations obtains the meta-object type reflecting the unparenthesized expression of the reflected parethesized expression
FunctionCallExpression
operations obtains the meta-object type reflecting the function in the reflected function-call-expression
FunctionalTypeConversion
operations obtains the meta-object type reflecting the constructor in reflected functional-type-conv-expression
Variable
and Function
operations get the address of the reflected variable or function, or the pointer-to-member value to the reflected non-static member
MemberFunction
operations checks if the reflected member function is declared with const, volatile, &, or && qualifier respectively
Record
and MemberFunction
operations checks if the reflected class or member function is marked with final
Variable
and MemberFunction
operations checks if the reflected variable is of static storage duration, or the reflected member function is static
SpecialMemberFunction
operations checks if the reflected special member function is implicitly declared
Constructor
and ConversionOperator
operations checks if the reflected constructor or conversion function is declared with explicit
MemberFunction
and Destructor
operations checks if the reflected member function is virtual
Lambda
operations obtains a meta-object sequence type whose elements reflect the captures of the reflected closure type
=
or &
respectively
operator()
of the reflected closure type is declared with const
LambdaCapture
operations checks if the reflected lambda capture is explicitly captured
__cpp_lib_reflection
(reflection TS)
a value of at least 201902 indicates that the support library of the Reflection TS is supportedThe following table lists that whether a meta-object type reflecting an operand satisfies concepts introduced by the Reflection TS.
Categoryreflexpr
operands Satisfied concepts Type class-name designating a union reflect::Union
class-name designating a closure type reflect::Lambda
class-name designating a non-union class reflect::Record
enum-name reflect::Enum
template type-parameter reflect::Type
, reflect::Alias
decltype-specifier reflect::Type
, reflect::Alias
type-name introduced by a using-declaration reflect::Type
, reflect::Alias
, reflect::ScopedMember
any other typedef-name reflect::Type
, reflect::Alias
any other type-id reflect::Type
Namespace namespace-alias reflect::Namespace
, reflect::Alias
the global namespace reflect::GlobalScope
any other namespace reflect::Namespace
Expression the name of a data member reflect::Variable
the name of a variable reflect::Variable
the name of an enumerator reflect::Enumerator
the name of a function parameter reflect::FunctionParameter
the name of a captured entity reflect::LambdaCapture
parenthesized expression reflect::ParenthesizedExpression
function-call-expression reflect::FunctionCallExpression
functional-type-conv-expression reflect::FunctionalTypeConversion
If the operand of the form id-expression is a constant expression, the type specified by the reflexpr-specifier also satisfies reflect::Constant
.
If the reflexpr-operand designates a class member, the type represented by the reflexpr-specifier also satisfies reflect::RecordMember
.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4