CppCon recently publicly released a video where Herb Sutter demos C++26 reflection features. It’s actually pretty exciting to me. As he mentions in the video, I’m not sure what other commercial-grade languages even have this feature.
Many languages offer some kind of reflection, though it has traditionally been a feature of interpreted languages, since full reflection requires the ability to understand and modify code directly.
I haven’t watched the video yet or read anything about how C++ intends to accomplish any of this, but it does seem an interesting idea.
Problem is, it is a design pattern looking for a solution. Compiled languages should not (generally) need reflection, IMHO — there are always other ways to accomplish the task that are less complex and more secure.
Don’t get me wrong, I _like_ reflection and introspection. It allows you to do some really cool stuff. (Which means, you can break stuff in simultaneously really cool and utterly rage-inducing ways.)
At my job we have utility programs that generate code, and I'm wondering if reflection features can remove some of this boilerplate. Maybe. I agree such features can add complexity and frustration if abused, but that's also every C++ feature.
The first thing I thought of is that it could help provide introspection of parts of the code/structs for "unit test"-esque checking as a sort of linter for specific contracts we want to enforce in the code.
The json example (9:20) and command-line argument example (13:01) look interesting to me.
Edit: Also, maybe it could provide easier-to-read/maintain alternatives to some template metaprogramming eldritch horrors, but I'm not sure about that yet.