C++26 - Static Reflection

Table of Contents

1. What Is Reflection?

Static reflection

2. Everything As Value

C++26 introduces two new operators. The reflection operator ^^ converts most name entity to std::meta::info type:

  constexpr std::meta::info rint = ^^int;

std::meta::info is a new, special, conexteval only, built-in type that can only reside in compile time. This reflection operator supports the following, they are called name entity.

  • ::, the global namespace
  • namespace name
  • Type ID, like int, double, etc.
  • ID expression, like variables, static member, field, function, template, enumerations.

We can convert the meta info back into the name entity, by using [:<meta-info>:]

  constexpr std::meta::info rint = ^^int;
  using int2 = [:rint:];

3. Meta Functions

We can do operations to retrieved meta info, such operations are called meta functions, which are defined in <meta> header.

3.1. Members

  namespace std::meta {
    consteval vector<info> members_of(info r, access_context ctx);
    consteval vector<info> bases_of(info r, access_context ctx);
    consteval vector<info> static_data_members_of(info r, access_context ctx);
    consteval vector<info> nonstatic_data_members_of(info r, access_context ctx);
    consteval vector<info> enumerators_of(info r, access_context ctx);

    consteval bool has_parent(info r);
    consteval info parent_of(info r);
  }

Date: 2026-06-29 Mon