C++ Reflection Cppcon demo

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.

https://youtu.be/7z9NNrRDHQU
What's reflection? The code being able to alter itself?
Yes, and more.

https://en.wikipedia.org/wiki/Reflective_programming

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.
Last edited on
Argh, my brain just doesn’t care enough to watch a 1.5 hour video.

Looks like we are looking at compile time reflection, and it appears to be an upgrade to the template metaprogramming system.



So, yeah, Chutlhu is coming to dinner.
I mean I didn’t watch the full video, I lost interest when they started talking about a system to replace C APIs as the lingua franca.

Like I mentioned in the other thread, there’s a lot of C++ features I haven’t kept up with.
Registered users can post here. Sign in or register to post.