Compile-Time Map and Compile-Time Mutable Variable with C++26 Reflection The article describes a method for creating compile-time key-value maps and a "compile-time mutable variable" using new reflection features introduced in C++26. It explains the underlying mechanisms, such as the `substitute`, `is_complete_type`, and `define_aggregate` functions, by first dissecting a compile-time ticket counter example from the C++26 reflection proposal (P2996R13). The author assumes the reader has a basic understanding of reflection and splice operators. Introduction Hello everyone. I would like to share with you a new method for creating compile-time key-value maps that I discovered while experimenting with the new features introduced in C++26. I will also show a new trick I call the compile-time mutable variable. I believe these methods will be very helpful in your stateful metaprogramming endeavors. Before continuing, you should have an understanding of what a reflection is and its basics. You should also know about the reflection and splice operators. If you do not, I recommend reading §4.1 and §4.2 of the “Reflection for C++26” P2996R13 https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p2996r13.html 1 paper. You do not need to know the other sections, as I will explain and reference them as necessary. To understand the new method, it’s best to start by dissecting the compile-time ticket counter example P2996R13 §3.17 . If you understand how it works, you can skip this section. Compile-Time Ticket Counter P2996R13 §3.17 The examples used in this section can be found on godbolt https://godbolt.org/z/on4xMe338 2 . The compile-time ticket counter is an example of how a compile-time counter could be made using the new features of reflection. The main goal of a compile-time counter is to be able to, during compilation, get the value of the counter and increment the value of the counter. This is useful for things such as automatically giving certain program elements unique numbers during compile-time, instead of manually setting the values and having to make sure that no duplicate numbers are given. The class TU Ticket has two static consteval functions: latest and increment . The latest function returns the latest current value of the counter, and the increment function increments the counter's value by one. To do this, TU Ticket uses three new functions introduced with reflection in C++26: substitute , is complete type , and define aggregate . These functions are part of the new namespace ‘meta’ and interact with reflections. You may have also noticed the consteval block, with the syntax: consteval { ...contents... } The contents of a consteval block will be evaluated once during compilation. This is mainly used for the define aggregate function and functions that will call define aggregate . For details, see P2996R13 §4.4.1. Substitute “Given a reflection for a template and reflections for template arguments that match that template, substitute returns a reflection for the entity obtained by substituting the given arguments in the template. ” p2996R13 §4.4.16 . Here’s a quick example to illustrate what a substitute does: template