Reflection library (since C++26) - cppreference.com
Namespaces
Variants

Reflection library (since C++26)

From cppreference.com
< cpp | meta
 
 
 
Reflection library
 
Reflection types and queries
Reflection queries
Reflection layout queries
Type properties
Type property queries
 

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

Template:cpp/meta/dsc is templateTemplate:cpp/meta/dsc is function templateTemplate:cpp/meta/dsc is variable templateTemplate:cpp/meta/dsc is class templateTemplate:cpp/meta/dsc is alias templateTemplate:cpp/meta/dsc is conversion function templateTemplate:cpp/meta/dsc is operator function templateTemplate:cpp/meta/dsc is literal operator templateTemplate:cpp/meta/dsc is constructor templateTemplate:cpp/meta/dsc is conceptTemplate:cpp/meta/dsc member offsetTemplate:cpp/meta/dsc data member optionsTemplate:cpp/meta/dsc is lvalue reference typeTemplate:cpp/meta/dsc is rvalue reference typeTemplate:cpp/meta/dsc is member object pointer typeTemplate:cpp/meta/dsc is member function pointer typeTemplate:cpp/meta/dsc is reflection typeTemplate:cpp/meta/dsc is reference typeTemplate:cpp/meta/dsc is arithmetic typeTemplate:cpp/meta/dsc is fundamental typeTemplate:cpp/meta/dsc is member pointer typeTemplate:cpp/meta/dsc is const typeTemplate:cpp/meta/dsc is volatile typeTemplate:cpp/meta/dsc is trivially copyable typeTemplate:cpp/meta/dsc is standard layout typeTemplate:cpp/meta/dsc is signed typeTemplate:cpp/meta/dsc is unsigned typeTemplate:cpp/meta/dsc is bounded array typeTemplate:cpp/meta/dsc is unbounded array typeTemplate:cpp/meta/dsc is scoped enum typeTemplate:cpp/meta/dsc is constructible typeTemplate:cpp/meta/dsc is default constructible typeTemplate:cpp/meta/dsc is copy constructible typeTemplate:cpp/meta/dsc is move constructible typeTemplate:cpp/meta/dsc is assignable typeTemplate:cpp/meta/dsc is copy assignable typeTemplate:cpp/meta/dsc is move assignable typeTemplate:cpp/meta/dsc is swappable with typeTemplate:cpp/meta/dsc is swappable typeTemplate:cpp/meta/dsc is destructible typeTemplate:cpp/meta/dsc is trivially constructible typeTemplate:cpp/meta/dsc is trivially default constructible typeTemplate:cpp/meta/dsc is trivially copy constructible typeTemplate:cpp/meta/dsc is trivially move constructible typeTemplate:cpp/meta/dsc is trivially assignable typeTemplate:cpp/meta/dsc is trivially copy assignable typeTemplate:cpp/meta/dsc is trivially move assignable typeTemplate:cpp/meta/dsc is trivially destructible typeTemplate:cpp/meta/dsc is nothrow constructible typeTemplate:cpp/meta/dsc is nothrow default constructible typeTemplate:cpp/meta/dsc is nothrow copy constructible typeTemplate:cpp/meta/dsc is nothrow move constructible typeTemplate:cpp/meta/dsc is nothrow assignable typeTemplate:cpp/meta/dsc is nothrow copy assignable typeTemplate:cpp/meta/dsc is nothrow move assignable typeTemplate:cpp/meta/dsc is nothrow swappable with typeTemplate:cpp/meta/dsc is nothrow swappable typeTemplate:cpp/meta/dsc is nothrow destructible typeTemplate:cpp/meta/dsc is implicit lifetime typeTemplate:cpp/meta/dsc has unique object representationsTemplate:cpp/meta/dsc reference constructs from temporaryTemplate:cpp/meta/dsc reference converts from temporaryTemplate:cpp/meta/dsc is same typeTemplate:cpp/meta/dsc is base of typeTemplate:cpp/meta/dsc is virtual base of typeTemplate:cpp/meta/dsc is convertible typeTemplate:cpp/meta/dsc is nothrow convertible typeTemplate:cpp/meta/dsc is layout compatible typeTemplate:cpp/meta/dsc is pointer interconvertible base of typeTemplate:cpp/meta/dsc is invocable typeTemplate:cpp/meta/dsc is invocable r typeTemplate:cpp/meta/dsc is nothrow invocable typeTemplate:cpp/meta/dsc is nothrow invocable r typeTemplate:cpp/meta/dsc remove constTemplate:cpp/meta/dsc remove volatileTemplate:cpp/meta/dsc remove cvTemplate:cpp/meta/dsc add constTemplate:cpp/meta/dsc add volatileTemplate:cpp/meta/dsc add cvTemplate:cpp/meta/dsc add lvalue referenceTemplate:cpp/meta/dsc add rvalue referenceTemplate:cpp/meta/dsc make signedTemplate:cpp/meta/dsc make unsignedTemplate:cpp/meta/dsc remove extentTemplate:cpp/meta/dsc remove all extentsTemplate:cpp/meta/dsc add pointerTemplate:cpp/meta/dsc remove cvrefTemplate:cpp/meta/dsc underlying typeTemplate:cpp/meta/dsc invoke resultTemplate:cpp/meta/dsc unwrap referenceTemplate:cpp/meta/dsc unwrap ref decayTemplate:cpp/meta/dsc tuple sizeTemplate:cpp/meta/dsc tuple elementTemplate:cpp/meta/dsc is applicable typeTemplate:cpp/meta/dsc is nothrow applicable typeTemplate:cpp/meta/dsc apply resultTemplate:cpp/meta/dsc variant sizeTemplate:cpp/meta/dsc variant alternativeTemplate:cpp/meta/dsc type order
Defined in header <meta>
(C++26)
the type of reflection values
(typedef) [edit]
exception thrown by reflection functions
(class) [edit]
Promoting compile-time storage into static storage
promotes a compile-time string to static storage, returning a reflection representing the static string
(function template) [edit]
promotes compile-time array into static storage, returning a reflection representing the static array
(function template) [edit]
promotes compile-time string to static storage, returning a pointer to the first character of the static string
(function template) [edit]
promotes compile-time array into static storage, returning a span of the static array
(function template) [edit]
promotes compile-time value into static storage, returning a pointer to the static object
(function template) [edit]
Operator representations
(C++26)
identifies overloadable operators
(enum) [edit]
identifies the operator represented by the reflection
(function) [edit]
converts a meta::operators enumerator to its symbolic name
(function) [edit]
Reflection names and locations
checks if reflection represents an entity that has an identifier
(function) [edit]
if the reflected entity has an identifier, obtains its name
(function) [edit]
obtains a string suitable for identifying the reflected entity
(function) [edit]
obtains the source location of the reflected entity
(function) [edit]
Reflection queries
(C++26)
determines the type of the reflected entity
(function) [edit]
(C++26)
obtains a reflection of the object of the reflected variable
(function) [edit]
obtains a reflection of the constant value of the reflected entity
(function) [edit]
checks if reflection represents a public, protected, or private member or base class
(function) [edit]
checks if reflection represents a virtual member function or virtual base class
(function) [edit]
checks if reflection represents a pure virtual member function
(function) [edit]
checks if reflection represents a member function that overrides another member function
(function) [edit]
(C++26)
checks if reflection represents a final class or final member function
(function) [edit]
checks if reflection represents a deleted function
(function) [edit]
checks if reflection represents a defaulted function
(function) [edit]
checks if reflection represents a user-provided function
(function) [edit]
checks if reflection represents a user-declared function
(function) [edit]
checks if reflection represents a member function that is declared explicit
(function) [edit]
checks if reflection represents a noexcept function or function type
(function) [edit]
checks if reflection represents a bit-field or a data member description of bit-field
(function) [edit]
checks if reflection represents an enumerator
(function) [edit]
checks if reflection represents an annotation
(function) [edit]
(C++26)
checks if reflection represents a const type or a function type with const qualifier
(function) [edit]
checks if reflection represents a volatile type or a function type with volatile qualifier
(function) [edit]
checks if reflection represents a mutable non-static data member
(function) [edit]
checks if the reflected entity is a ref qualified member function
(function) [edit]
checks if the reflected entity has a storage duration
(function) [edit]
checks if the reflected entity has a linkage
(function) [edit]
checks if the reflected entity has "C" language linkage (extern "C")
(function) [edit]
checks if reflection represents a complete type
(function) [edit]
checks if the reflected type has its list of members completely defined
(function) [edit]
checks if reflection represents a variable
(function) [edit]
(C++26)
checks if reflection represents a type
(function) [edit]
checks if reflection represents a namespace
(function) [edit]
checks if reflection represents a type alias
(function) [edit]
checks if reflection represents a namespace alias
(function) [edit]
checks if reflection represents a function
(function) [edit]
checks if reflection represents a conversion function
(function) [edit]
checks if reflection represents an operator overload
(function) [edit]
checks if reflection represents a user-defined literal operator
(function) [edit]
checks if reflection represents a special member function
(function) [edit]
checks if the reflected entity is a constructor of this kind
(function) [edit]
checks if the reflected entity is an assignment operator of this kind
(function) [edit]
checks if the reflected entity is a destructor
(function) [edit]
checks if reflection represents a function parameter
(function) [edit]
checks if reflection represents an explicit object parameter
(function) [edit]
checks if reflected function parameter has a default argument
(function) [edit]
checks if reflection represents a function or function type with an ellipsis parameter
(function) [edit]
(C++26)
checks if reflection represents a (scalar) value
(function) [edit]
(C++26)
checks if reflection represents a static object
(function) [edit]
checks if reflection represents a structured binding
(function) [edit]
checks if reflection represents a class member
(function) [edit]
checks if reflection represents a namespace member
(function) [edit]
checks if reflection represents a non-static data member
(function) [edit]
checks if reflection represents a static class member
(function) [edit]
(C++26)
checks if reflection represents a direct base class relationship
(function) [edit]
checks if reflected non-static data member has a default member initializer
(function) [edit]
checks if the reflected entity is contained in a scope
(function) [edit]
(C++26)
obtains the scope that contains the reflected entity
(function) [edit]
(C++26)
determines the underlying entity of the reflected type/namespace alias
(function) [edit]
checks if reflected entity is produced by substituting template arguments into a template
(function) [edit]
determines the template used to instantiate the reflected entity
(function) [edit]
obtains the template arguments of the reflected entity
(function) [edit]
obtains the parameters of the reflected function
(function) [edit]
obtains the variable of the reflected function parameter in the function definition
(function) [edit]
obtains the return type of the reflected function
(function) [edit]
Accessibility queries
represents a context for access checking
(class) [edit]
checks if a member is accessible in a given context
(function) [edit]
checks if the reflected class has any inaccessible non-static data members
(function) [edit]
checks if the reflected class has any inaccessible direct base classes
(function) [edit]
checks if the reflected class has any inaccessible non-static data members or direct base classes
(function) [edit]
Scope identification
returns a reflection of the enclosing function
(function) [edit]
returns a reflection of the enclosing class
(function) [edit]
returns a reflection of the enclosing namespace
(function) [edit]
Reflection member queries
obtains the accessible direct members of the reflected class or namespace
(function) [edit]
(C++26)
obtains the accessible direct bases of the reflected class
(function) [edit]
obtains the accessible static data members of the reflected class
(function) [edit]
obtains the accessible non-static data members of the reflected class
(function) [edit]
obtains the accessible base class subobjects and non-static data members of the reflected class
(function) [edit]
obtains the enumerators of the reflected enum type
(function) [edit]
Reflection layout queries
(C++26)
returns the offset of a (member or base) subobject relative to its enclosing class
(function) [edit]
(C++26)
returns the size in bytes of the reflected object or type
(function) [edit]
returns the alignment of the reflected object or type
(function) [edit]
returns the size in bits of the reflected object or type
(function) [edit]
Annotation reflection
obtains the annotations applying to the reflected entity
(function) [edit]
obtains the annotations that apply to the reflected entity and have the specified type
(function) [edit]
Value extraction
(C++26)
extracts the value of the reflected entity
(function template) [edit]
Reflection substitution
specifies a range of reflection values
(concept) [edit]
checks whether the reflected arguments can be substituted in the reflected template
(function template) [edit]
substitutes reflected arguments in the reflected template
(function template) [edit]
Expression result reflection
returns a reflection representing a value or template parameter object, suitable for use as a constant template argument
(function template) [edit]
returns a reflection representing an object, suitable for use as a constant template argument
(function template) [edit]
returns a reflection representing a function, suitable for use as a constant template argument
(function template) [edit]
Class definition generation
creates a data member description for use with injected declarations
(function) [edit]
checks if reflection represents a data member description
(function) [edit]
defines an aggregate type from a sequence of data member descriptions
(function template) [edit]
Primary type categories
checks if reflected type is void
(function) [edit]
checks if reflected type is std::nullptr_t
(function) [edit]
checks if reflected type is an integral type
(function) [edit]
checks if reflected type is a floating-point type
(function) [edit]
checks if reflected type is an array type
(function) [edit]
checks if reflected type is a pointer type
(function) [edit]
checks if reflected type is an enumeration type
(function) [edit]
checks if reflected type is a union type
(function) [edit]
checks if reflected type is a non-union class type
(function) [edit]
checks if reflected type is a function type
(function) [edit]
Composite type categories
checks if reflected type is an object type
(function) [edit]
checks if reflected type is a scalar type
(function) [edit]
checks if reflected type is a compound type
(function) [edit]
Type properties
checks if reflected type is a standard-layout type
(function) [edit]
checks if reflected type is a polymorphic class type
(function) [edit]
checks if reflected type is an abstract class type
(function) [edit]
checks if reflected type is a final class type
(function) [edit]
checks if reflected type is an aggregate type
(function) [edit]
checks if reflected type is a structural type
(function) [edit]
checks if reflected type has a virtual destructor
(function) [edit]
Type property queries
(C++26)
obtains the number of dimensions of reflected array type
(function) [edit]
(C++26)
obtains the size of reflected array type along a specified dimension
(function) [edit]
Type relations
Const-volatile modifications
Reference modifications
removes a reference from reflected type
(function) [edit]
Sign modifications
Array modifications
Pointer modifications
removes a pointer from reflected type
(function) [edit]
Other transformations
(C++26)
applies type transformations as when passing a function argument by value
(function) [edit]
determines the common type of a sequence of reflected types
(function) [edit]
determines the common reference type of a sequence of reflected types
(function) [edit]
Checking string literals
checks if a pointer points into a string literal
(function) [edit]

Notes

Feature-test macro Value Std Feature
__cpp_lib_reflection 202506L (C++26) <meta>: Reflection library support.
Constexpr exceptions as error handling in reflection.

Example