C++26 Reflections adventures and compile-time UML
36 comments
·August 3, 2025matt123456789
Whenever I start to feel like a real programmer making games and webapps and AI-enhanced ETL pipelines, I inevitably come across the blog post of a C++ expert and reminded that I am basically playing with legos and play-doh.
tw061023
It's the other way around. You are the real programmer and the committee and the "modern C++" crowd are more interested playing with legos instead of shipping actual software.
No way anything std::meta gets into serious production; too flexible in some ways, too inflexible in others, too much unpredictability, too high impact on compilation times - just like always with newer additions to the C++ standard. It takes one look at coding standards of real-world projects to see how irrelevant this stuff is.
And like always, the problem std::meta is purported to solve has been solved for years.
jandrewrogers
The stream of modern C++ features have been a god-send for anyone that cares about high-performance, high-reliability software. Maybe that doesn’t apply to your use case but C++ is widely used in critical data infrastructure. For anyone that does care about things like performance and reliability, the changes to modern C++ have largely been obvious and immediately useful improvements. Almost all C++ projects I know in the high-performance data infrastructure space live as close to the bleeding edge of new C++ features as the compiler implementations make feasible.
And no, reflection hasn’t “been solved for years” unless you have a very misleading definition of “solved”. A lot of the C++ code I work with is heavily codegen-ed via metaprogramming. Despite the relative expressiveness and flexibility of C++ metaprogramming, proper reflection will dramatically improve what is practical in a strict and type-safe way at compile-time.
tw061023
I am sorry, but this reads like GPT.
Which projects? Which features? What exactly was the impact on performance and reliability, how and why? How did critical projects adopt the stream of features, considering nobody sane touches nothing in a new C++ standard for a decade, waiting for DRs to settle and for codegen stopping to suck?
Reflection has been solved for years with custom codegen, including dimensions which std::meta cannot even touch such as stable cross-platform, cross-compiler ABI.
funkychicken
I know the trading firm I work at will be making heavy use of reflection the second it lands… we had a literal party when it made it into the standard.
mylons
sure, but instagram was created by a handful of people with python and got a billion dollar exit in 2012.
pjmlp
I bet CERN might eventually replace their Python based code generators with C++26 reflection.
tw061023
Which problem would this solve for them?
throwaway9832
Every problem is solved. We should stop making anything. Specially CRUD apps, because how is that even programming? What does it solve that hasn't been solved?
This line of thinking is not productive. It is a mistake to see yourself as what you do, because then you're cornering yourself into defending it, no matter what.
null
d_tr
What's the solution that's been around for years?
> ... just like always with newer additions to the C++ standard.
This is objectively laughable.
mpyne
I was literally running into something a couple of days ago on my toy C++ project where basic compile-time reflection would have been nice to have for some sanity checking.
And even if it's true that some things can be done already with specific compilers and implementation-specific hacks, it would be really nice to be able to do those things more straightforwardly.
My experience with C++ changes has been that the recent additions to compile-time metaprogramming operations is that they improve compile times rather than make it worse, because you don't have to do things like std::enable_if<> hacks and recursive templates to do things that a simple generic lambda or constexpr conditional will do, which are more difficult for both you and the compiler.
jcranmer
> What's the solution that's been around for years?
Build tools to generate C++ code from some other tool. Interface description languages, for example, or something like (going back decades here) lex and yacc even.
DLoupe
For example, boost library's "describe" and similar macro based solutions. Been using this for many years.
tw061023
Whip up some kind of in-house IDL/DDL parser, codegen from that.
Which, precisely, additions do not fit my points?
lmariscal
I would argue that C++ expertise doesn't necessarily correlate to the complexity of the software being developed. Although I do try to learn the fancy new features I know many developers who even though they are still only using C++11 features they are creating some very complex and impactful pieces of software.
lanyard-textile
I definitely think that’s not a coincidence. C++11 is where you get the most useful feature tradeoffs with reasonable costs.
Smart pointers being a great example. Shared ptr has its issues, it isn’t the most performant choice in most cases, but it by far reduces more footguns than it introduces.
Compared to something like std::variant in the C++17 standard that comes with poor enough performance issues that it’s rarely ever a good fit.
tombert
I'm not a C++ developer at all, but unless I'm missing something this didn't seem terribly difficult?
This isn't meant to make myself seem smart or to try and make you seem dumb, I'm just curious what was confusing about this even from a high-level perspective. It felt like a clever but not too atypical metaprogramming thing.
Maybe I've just done too much Clojure.
rramadass
I know your comment was meant as a tongue in cheek funny one but people should not be intimidated/overawed by the size of the C++ feature set. You don't need to know nor use all of them but can pick and choose based on your needs and how you model your problem. Also much of the complexity is perceived rather than real since it takes time for one to understand and assimilate new concepts. You can program very effectively and productively using just C++98 features (along with C if needed) with no hint of "Modern C++" (never mind the fanbois :-) What this gives you is the ability to use a single language to tackle small constrained microcontrollers with very limited toolchain support all the way to using the latest and the greatest toolchain on top-of-line processors.
tombert
I had to do a UML thing for the first time in years for a class a few weeks ago[2].
I'm not 100% convinced that UML is actually useful at all. Obviously if you find value from it, don't let me take that from you, by all means keep doing it, but all it seemed to provide was boxes pointing to other boxes for stuff that really wasn't unclear from looking directly at the code anyway. It's really not that hard to look directly at the class and look directly at the "extends" keyword (or the equivalent for whatever language you're using) and then follow from there. Maybe if you had like ten layers of inheritance it could be valuable, but if you're doing ten layers of inheritance there's a good chance that your code will be incomprehensible regardless.
I'm not against visual diagrams for code, I draw logic out with Draw.io all the time and I've been hacking on the RoboTool [1] toolkit a bit in my free time, but what UML offers always felt more masturbatory than useful.
Maybe I'm wrong, it certainly wouldn't be the first time, but every time I've tried to convince myself to like it I've left a little disappointed. It always kind of felt like stuff the enterprise world does to look like they're working hard and creating value.
[1] https://robostar.cs.york.ac.uk/robotool/
ETA:
[2] By "class", I meant like an education class, not a Java class.*
delusional
This is interesting because it interacts with consteval. It would be cool if the standards committee could so somehow figure out how to do codegen from consteval. Then we'd be kinda close to the promised land of procedural macros written in real C++.
peapicker
Still waiting for IBMi to support C++11.
Reflection really was the missing piece, it's one of the things that are so nice in Java. Being able to serialize/deserialize a struct to JSON fully dynamically saves a lot of code.