r/cpp • u/Reflection_is_great • May 11 '26
The Heap: Compile-Time Map and Compile-Time Mutable Variable with C++26 Reflection
https://stackoverflow.blog/2026/05/11/compile-time-map-and-compile-time-mutable-variable-with-c-26-reflection/Stack Overflow is introducing The Heap, a place for community articles. I had the privilege of having my article one of the first to be published on it.
It is about how you can use the new reflection features to create compile-time maps and a trick I call the compile-time mutable variable. I hope you can learn something new from it!
If you have an interesting article, I encourage you to try submitting it to The Heap!
82
Upvotes
View all comments
Show parent comment
4
u/Reflection_is_great May 11 '26
This is great to hear. I saw your post about cvl just before I posted this, so I haven't dissected it yet.
You're right about using substitute instead of passing the values as template parameters.
I haven’t experimented much with friend injection, so I’m excited to see how our similar ideas are implemented differently! I found that the main limit of the define_aggregate approach is being in the same scope, as you said. I’m happy to see that this problem has a solution. I also like how ergonomic the syntax for cvl is. I never thought of using a consteval assignment operator for this kind of thing.
I find it fun that by solving the same problem with different approaches, we have a convergent evolution with our solutions, like layering consteval variable over list, and layering list over map.
Reflection has definitely opened the language to new horizons. I'm excited to see what else people will create using it!