cpp/experimental/reflect

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

reflexpr-specifier
A is of form   , and specifies a meta-object type (see below).

can be one of following:

where is

and are following sorts of expressions which perform explict cast:

The operand to the shall be a type, namespace, enumerator, variable, data member, function parameter, captured entity,  or, and parenthesized expression. reflects the global namespace.

For a of form  , the  shall be a (possibly multi-parenthesized)  or.

If an unparenthesized operand can be treated as either a or a, then it is treated as a. Parenthesizes can be used for disambiguation between function-style cast and a. For example, given a class type with default constructor,  reflects the function type, and  reflects the expression.

If the operand designates both an alias and a class name, the type represented by the reflexpr-specifier reflects the alias and satisfies.

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.

Meta-object types
A meta-object type is an unnamed, incomplete namespace-scope class type. A type satisfies the concept if and only if it is a meta-object type. Meta-object types may satisfy other concepts, depending on the operand to.

It is unspecified whether repeatedly applying 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 through type traits or type transformations on it.

Overload resolution
If the of the  is of class type, i.e.  in the   is of class type, then the user-defined conversion function of the type of the   shall not be used.

If is not of class type, it shall name a function that is the unique result of overload resolution.

Reflection-related
An alias is a name introduced by a declaration, an alias-declaration, or a using-declaration.

An entity or alias is reflection-related to an entity or alias  if Reflection-relation relationship is reflexive and transitive, but not symmetric.
 * 1)  and  are the same entity or alias,
 * 2)  is a variable or enumerator and  is the type of ,
 * 3)  is an enumeration and  is the underlying type of ,
 * 4)  is a class and  is a member or base class of ,
 * 5)  is a non-template alias that designates the entity ,
 * 6)  is not the global namespace and  is an enclosing class or namespace of ,
 * 7)  is the parenthesized expression ,
 * 8)  is a lambda capture of the closure type ,
 * 9)  is the closure type of the lambda capture ,
 * 10)  is the type specified by the  ,
 * 11)  is the function selected by overload resolution for a  ,
 * 12)  is the return type, a parameter type, or function type of the function, or
 * 13)  is reflection-related to an entity or alias  and  is reflection-related to.

Informally speaking, the case that is reflection-related to  means that  participates in the declaration or definition of.

Zero or more successive applications of type transformations that yield meta-object types to the type denoted by a 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.

Miscellaneous

 * An expression used as is an unevaluated expressions and potentially constant evaluated.
 * For the purpose of determination of variables captured in a lambda expression by a capture-default, a operand is not considered to be an unevaluated operand.
 * A function or variable of static storage duration reflected by meta-object type is odr-used by the specialization, as if by taking the address of an id-expression nominating the function or variable.
 * There can be more than one definition of a meta-object type, as long as all operations on this type yield the same constant expression results.
 * A type is dependent if it is denoted by a reflexpr-specifier, and the operand
 * is a type-dependent expression or a (possibly parenthesized) with at least one type-dependent immediate subexpression, or
 * designates a dependent type or a member of an unknown specialization or a value-dependent constant expression.

Satisfaction of concepts
The following table lists that whether a meta-object type reflecting an operand satisfies concepts introduced by the Reflection TS.

If the operand of the form id-expression is a constant expression, the type specified by the reflexpr-specifier also satisfies.

If the reflexpr-operand designates a class member, the type represented by the reflexpr-specifier also satisfies.