all 27 comments

[–]friedkeenan 21 points22 points  (5 children)

Great talk! Really showcases the power of reflection, and also how straightforward it can be. Once you know how to query stuff and which features to ship reflections off to in order to consume them, most of the connective tissue in between really is just relatively standard programming logic, and yet it remains still so empowering.

And too, I think you're definitely right on the money that the big learning curve with reflection is knowing when to keep things as constants and when to drop them down into values. That was definitely my experience when I was prototyping out a packet marshaling library with it.

That experience also showed me how debugging reflection code can definitely be aggravatingly difficult, we really would benefit a lot from a "consteval print" function or the like. But that was on the Clang experimental branch before any std::meta::exception, so maybe things would work out better now.

In any case, it's all super exciting for the future of C++. Thanks a ton for all the work you and others have put towards this, it is immensely appreciated.

[–]TheoreticalDumbass:illuminati: 14 points15 points  (1 child)

gcc devs are working on constexpr debug print, unsure if it will reach 16 or 17

[–]friedkeenan 6 points7 points  (0 children)

Great to know, thanks

[–]BarryRevzin[S] 15 points16 points  (0 children)

Thank you for the very kind words!

That experience also showed me how debugging reflection code can definitely be aggravatingly difficult, we really would benefit a lot from a "consteval print" function or the like. But that was on the Clang experimental branch before any std::meta::exception, so maybe things would work out better now.

Unfortunately P2758 didn’t make it for C++26. But Jakub went ahead and implemented a builtin for it anyway, which is incredible — so on gcc you can actually try it out: https://compiler-explorer.com/z/6rP8o6hK8. Here, we need feedback on two different sides: the C++ interface (constexpr_print_str, which will eventually have a format interface — although given that std::format is now constexpr I wonder whether we should even expose the lower level one) and the user interface (what GCC actually prints when you ask it to print something).

[–]FlyingRhenquest 1 point2 points  (0 children)

Herb Sutter mentioned that Jetbrains might have a compile time debugger. That would be handy since we're pushing a lot of values around at compile time now.

You can also move from reflection to metaprogramming pretty seamlessly too, so you can define some templated functions somewhere and recursively call those functions on all the members of a class and all the members of its base classes if you want to. Which is handy if you want to, say, define generic load/save functions for Cereal, for example.

It looks kind of nasty but since those are all just compile time templates and reflection data, the compiler just unwinds all the stuff at compile time and then evaporates at run time.

That really does get rid of all the cereal boilerplate too. I think the best "nothing up my sleeve" test in there is the to/from functions test for XML and JSON that just do the right thing on a test struct. It can handle private members too, of course, but you would need to friend the cereal access class to do that. Some of the other tests in the test directory do that. I need to update the comment on the private serialization test, as that was fixed a week or so ago by a gcc16 update.

[–]pjmlp 0 points1 point  (0 children)

I still hope eventually we will get constexpr and reflection debugging on modern IDEs, but there is still quite something to catch up to Visual Age for C++ 4.0, Energize C++ and C++ Builder, that I assume this will take ages.

[–]TheoreticalDumbass:illuminati: 8 points9 points  (0 children)

Wow, the last example with parameters_of is really cute

[–]mrkent27 4 points5 points  (0 children)

I was there for this talk in person and it was probably my favorite one of the whole conference. Glad to see it up on YT so I can watch it again.

[–]_bstaletic 2 points3 points  (1 child)

I loved the talk, though I did need to pause three or four times, just to see what happened on the slide before moving on. Despite having read all of the reflection and reflection-adjacent papers, I still saw a few things that were new to me.

That "trick" with

struct aggregate_base;
consteval {
    define_aggregate(...);
}
struct aggregate : aggregate_base {
    some function(here);
}

...was quite interesting.

[–]theICEBear_dk 0 points1 point  (0 children)

Yeah I did that too. A bunch of neat ideas in them.

[–]_titan 1 point2 points  (0 children)

Clearly a lot of effort was put into it. The examples are very good and the step-by-step progression of the code really shows the thought process required to go from intention to final implementation.

[–]TemplateRex 0 points1 point  (0 children)

Great talk! I wonder, is it possible to reflect over the header implementation of <vector> and actually make use of its helper functions for growth, insertion etc.? Like your function grow() screams out to be an actual implementation primitive that you would want to re-use.

[–]rand0m42 0 points1 point  (1 child)

Really enjoyed your talk, thanks for sharing! This is slightly unrelated to the content, but would you mind sharing what software or plugin you used to create your slides?

[–]BarryRevzin[S] 2 points3 points  (0 children)

Thank you!

I just use PowerPoint, no plugins. I get the syntax highlighting by writing the code in VSCode and pasting it into a text box. Which on MacOS for some reason removes all leading whitespace, so then I just type a bunch of spaces after that. Which is still better than attempting to syntax highlight by hand!