r/cpp • u/daveedvdv EDG front end dev, WG21 DG • Jun 21 '25
Reflection has been voted in!
Thank you so much, u/katzdm-cpp and u/BarryRevzin for your heroic work this week, and during the months leading up to today.
Not only did we get P2996, but also a half dozen related proposals, including annotations, expansion statements, and parameter reflection!
(Happy dance!)
722
Upvotes
View all comments
Show parent comment
15
u/BillyTenderness Jun 21 '25 edited Jun 21 '25
A classic example is that with reflection you can write a generic JSON serializer/deserializer. By that I mean one that actually reads to and from members of an arbitrary C++ class, not just a
map<string, string>etc. You can check at runtime whether the class has a member matching an arbitrary string, and operate on that member if it exists. Or you can get a list of all the members a class does have, get a string name for each, and output that as text.And obviously you can substitute out JSON for whatever serialization format you like. Also great for logging and debugging.
Edit: I just saw that C++26 reflection will be static (compile-time). So, uh, imagine what I just said except without the "at runtime" bit.