Reflection library (since C++26)
From cppreference.com
The facilities defined in this section support reflective programming, allowing C++ programs to both observe the structure of the program itself and to generate code that depends on those observations.
Core language
The reflection library works in conjunction with two core language features:
Reflection library
| This section is incomplete |
Defined in header
<meta> | |
(C++26) |
the type of reflection values (typedef) |
(C++26) |
exception thrown by reflection functions (class) |
Promoting compile-time storage into static storage | |
(C++26) |
promotes a compile-time string to static storage, returning a reflection representing the static string (function template) |
(C++26) |
promotes compile-time array into static storage, returning a reflection representing the static array (function template) |
(C++26) |
promotes compile-time string to static storage, returning a pointer to the first character of the static string (function template) |
(C++26) |
promotes compile-time array into static storage, returning a span of the static array (function template) |
(C++26) |
promotes compile-time value into static storage, returning a pointer to the static object (function template) |
Operator representations | |
(C++26) |
identifies overloadable operators (enum) |
(C++26) |
identifies the operator represented by the reflection (function) |
(C++26) |
converts a meta::operators enumerator to its symbolic name (function) |
Reflection names and locations | |
(C++26) |
checks if reflection represents an entity that has an identifier (function) |
(C++26) |
if the reflected entity has an identifier, obtains its name (function) |
| obtains a string suitable for identifying the reflected entity (function) | |
(C++26) |
obtains the source location of the reflected entity (function) |
Reflection queries | |
(C++26) |
determines the type of the reflected entity (function) |
(C++26) |
obtains a reflection of the object of the reflected variable (function) |
(C++26) |
obtains a reflection of the constant value of the reflected entity (function) |
| checks if reflection represents a public, protected, or private member or base class (function) | |
(C++26) |
checks if reflection represents a virtual member function or virtual base class (function) |
(C++26) |
checks if reflection represents a pure virtual member function (function) |
(C++26) |
checks if reflection represents a member function that overrides another member function (function) |
(C++26) |
checks if reflection represents a final class or final member function (function) |
(C++26) |
checks if reflection represents a deleted function (function) |
(C++26) |
checks if reflection represents a defaulted function (function) |
(C++26) |
checks if reflection represents a user-provided function (function) |
(C++26) |
checks if reflection represents a user-declared function (function) |
(C++26) |
checks if reflection represents a member function that is declared explicit (function) |
(C++26) |
checks if reflection represents a noexcept function or function type (function) |
(C++26) |
checks if reflection represents a bit-field or a data member description of bit-field (function) |
(C++26) |
checks if reflection represents an enumerator (function) |
(C++26) |
checks if reflection represents an annotation (function) |
(C++26) |
checks if reflection represents a const type or a function type with const qualifier (function) |
(C++26) |
checks if reflection represents a volatile type or a function type with volatile qualifier (function) |
(C++26) |
checks if reflection represents a mutable non-static data member (function) |
| checks if the reflected entity is a ref qualified member function (function) | |
| checks if the reflected entity has a storage duration (function) | |
| checks if the reflected entity has a linkage (function) | |
(C++26) |
checks if the reflected entity has "C" language linkage (extern "C") (function) |
(C++26) |
checks if reflection represents a complete type (function) |
(C++26) |
checks if the reflected type has its list of members completely defined (function) |
(C++26) |
checks if reflection represents a variable (function) |
(C++26) |
checks if reflection represents a type (function) |
(C++26) |
checks if reflection represents a namespace (function) |
(C++26) |
checks if reflection represents a type alias (function) |
(C++26) |
checks if reflection represents a namespace alias (function) |
(C++26) |
checks if reflection represents a function (function) |
(C++26) |
checks if reflection represents a conversion function (function) |
(C++26) |
checks if reflection represents an operator overload (function) |
(C++26) |
checks if reflection represents a user-defined literal operator (function) |
(C++26) |
checks if reflection represents a special member function (function) |
| checks if the reflected entity is a constructor of this kind (function) | |
| checks if the reflected entity is an assignment operator of this kind (function) | |
(C++26) |
checks if the reflected entity is a destructor (function) |
(C++26) |
checks if reflection represents a function parameter (function) |
(C++26) |
checks if reflection represents an explicit object parameter (function) |
(C++26) |
checks if reflected function parameter has a default argument (function) |
(C++26) |
checks if reflection represents a function or function type with an ellipsis parameter (function) |
(C++26) |
checks if reflection represents a (scalar) value (function) |
(C++26) |
checks if reflection represents a static object (function) |
(C++26) |
checks if reflection represents a structured binding (function) |
(C++26) |
checks if reflection represents a class member (function) |
(C++26) |
checks if reflection represents a namespace member (function) |
(C++26) |
checks if reflection represents a non-static data member (function) |
(C++26) |
checks if reflection represents a static class member (function) |
(C++26) |
checks if reflection represents a direct base class relationship (function) |
| checks if reflected non-static data member has a default member initializer (function) | |
(C++26) |
checks if the reflected entity is contained in a scope (function) |
(C++26) |
obtains the scope that contains the reflected entity (function) |
(C++26) |
determines the underlying entity of the reflected type/namespace alias (function) |
(C++26) |
checks if reflected entity is produced by substituting template arguments into a template (function) |
(C++26) |
determines the template used to instantiate the reflected entity (function) |
(C++26) |
obtains the template arguments of the reflected entity (function) |
(C++26) |
obtains the parameters of the reflected function (function) |
(C++26) |
obtains the variable of the reflected function parameter in the function definition (function) |
(C++26) |
obtains the return type of the reflected function (function) |
Accessibility queries | |
(C++26) |
represents a context for access checking (class) |
(C++26) |
checks if a member is accessible in a given context (function) |
| checks if the reflected class has any inaccessible non-static data members (function) | |
(C++26) |
checks if the reflected class has any inaccessible direct base classes (function) |
(C++26) |
checks if the reflected class has any inaccessible non-static data members or direct base classes (function) |
Scope identification | |
(C++26) |
returns a reflection of the enclosing function (function) |
(C++26) |
returns a reflection of the enclosing class (function) |
(C++26) |
returns a reflection of the enclosing namespace (function) |
Reflection member queries | |
(C++26) |
obtains the accessible direct members of the reflected class or namespace (function) |
(C++26) |
obtains the accessible direct bases of the reflected class (function) |
(C++26) |
obtains the accessible static data members of the reflected class (function) |
(C++26) |
obtains the accessible non-static data members of the reflected class (function) |
(C++26) |
obtains the accessible base class subobjects and non-static data members of the reflected class (function) |
(C++26) |
obtains the enumerators of the reflected enum type (function) |
Reflection layout queries | |
(C++26) |
returns the offset of a (member or base) subobject relative to its enclosing class (function) |
(C++26) |
returns the size in bytes of the reflected object or type (function) |
(C++26) |
returns the alignment of the reflected object or type (function) |
(C++26) |
returns the size in bits of the reflected object or type (function) |
Annotation reflection | |
(C++26) |
obtains the annotations applying to the reflected entity (function) |
(C++26) |
obtains the annotations that apply to the reflected entity and have the specified type (function) |
Value extraction | |
(C++26) |
extracts the value of the reflected entity (function template) |
Reflection substitution | |
(C++26) |
specifies a range of reflection values (concept) |
(C++26) |
checks whether the reflected arguments can be substituted in the reflected template (function template) |
(C++26) |
substitutes reflected arguments in the reflected template (function template) |
Expression result reflection | |
(C++26) |
returns a reflection representing a value or template parameter object, suitable for use as a constant template argument (function template) |
(C++26) |
returns a reflection representing an object, suitable for use as a constant template argument (function template) |
(C++26) |
returns a reflection representing a function, suitable for use as a constant template argument (function template) |
Class definition generation | |
(C++26) |
creates a data member description for use with injected declarations (function) |
(C++26) |
checks if reflection represents a data member description (function) |
(C++26) |
defines an aggregate type from a sequence of data member descriptions (function template) |
Primary type categories | |
(C++26) |
checks if reflected type is void (function) |
(C++26) |
checks if reflected type is std::nullptr_t (function) |
(C++26) |
checks if reflected type is an integral type (function) |
(C++26) |
checks if reflected type is a floating-point type (function) |
(C++26) |
checks if reflected type is an array type (function) |
(C++26) |
checks if reflected type is a pointer type (function) |
(C++26) |
checks if reflection represents an lvalue reference (function) |
(C++26) |
checks if reflection represents an rvalue reference (function) |
(C++26) |
checks if reflected type is an enumeration type (function) |
(C++26) |
checks if reflected type is a union type (function) |
(C++26) |
checks if reflected type is a non-union class type (function) |
(C++26) |
checks if reflected type is a function type (function) |
Composite type categories | |
(C++26) |
checks if reflection represents either an lvalue reference or rvalue reference (function) |
(C++26) |
checks if reflection represents an arithmetic type (function) |
(C++26) |
checks if reflection represents a fundamental type (function) |
(C++26) |
checks if reflected type is an object type (function) |
(C++26) |
checks if reflected type is a scalar type (function) |
(C++26) |
checks if reflected type is a compound type (function) |
Type properties | |
(C++26) |
checks if reflection represents a const-qualified type (function) |
(C++26) |
checks if reflection represents a volatile-qualified type (function) |
(C++26) |
checks if reflection represents a trivially copyable type (function) |
(C++26) |
checks if reflected type is a standard-layout type (function) |
(C++26) |
checks if reflected type is a class (but not union) type and has no non-static data members (function) |
(C++26) |
checks if reflected type is a polymorphic class type (function) |
(C++26) |
checks if reflected type is an abstract class type (function) |
(C++26) |
checks if reflected type is a final class type (function) |
(C++26) |
checks if reflected type is an aggregate type (function) |
(C++26) |
checks if reflected type is a structural type (function) |
(C++26) |
checks if reflection represents a signed arithmetic type (function) |
(C++26) |
checks if reflection represents an unsigned arithmetic type (function) |
(C++26) |
checks if reflected type has a virtual destructor (function) |
Type property queries | |
(C++26) |
obtains the number of dimensions of reflected array type (function) |
(C++26) |
obtains the size of reflected array type along a specified dimension (function) |
Type relations | |
(C++26) |
checks if two reflections represent the same types (function) |
(C++26) |
checks if two reflections represent types such that one type is a base of the other type (function) |
Const-volatile modifications | |
Reference modifications | |
(C++26) |
removes a reference from reflected type (function) |
Sign modifications | |
Array modifications | |
Pointer modifications | |
(C++26) |
removes a pointer from reflected type (function) |
Other transformations | |
(C++26) |
applies type transformations as when passing a function argument by value (function) |
(C++26) |
determines the common type of a sequence of reflected types (function) |
(C++26) |
determines the common reference type of a sequence of reflected types (function) |
Checking string literals | |
(C++26) |
checks if a pointer points into a string literal (function) |
Notes
| Feature-test macro | Value | Std | Feature |
|---|---|---|---|
__cpp_lib_reflection |
202506L |
(C++26) | <meta>: Reflection library support. Constexpr exceptions as error handling in reflection. |
