Oof, that first example (the idiomatic C++26 way) looks so foreign if you're mostly used to C++11.
ginko•55m ago
Is it? I'm mostly used to (pre-)C++11 and the only unusual operators I see are ^^T (which I presume accesses the metadata info of T) and [:e:] (which I assume somehow casts the enumerator metadata 'e' to a constant value of T).
And template for but I assume that's like inline for like in zig.
CamouflagedKiwi•26m ago
requires is also new (not sure exactly when that appeared, it's after the last time I wrote C++ in anger) although I think it's fairly clear what it means. I can only guess at the other two.
Not familiar with Zig but AFAICT `inline for` is about instructing the compiler to unroll the loop, whereas `template for` means it can be evaluated at compile time and each loop iteration can have a different type for the iteration variable. It's a bit crazy but necessary for reflection to work usefully in the way the language sets it up.
I was a fool to assume that the same forces shaping the ugliness of C++ syntax would not also be at work in C++ 26.
w4rh4wk5•57m ago
I've been wondering about debug-ability of code using reflection. X-Macros are quite annoying to step through in most debuggers, though possible. While the code in the first example is evaluated fully at compile-time, how would you approach debugging it?
HarHarVeryFunny•40m ago
No doubt reflection has been built with other use cases in mind, but it sure would have been nice just to have std::to_string(enum)
bluGill•28s ago
C++ conference speakers (including keynotes) are now begging everyone to stop using enum to string in their example. While they are a simple and easy to understand example, reflection is for much more interesting problems. I can't think of any other example that I would type into a comment box or put on a slide.
king_geedorah•12m ago
Another win for X macros and for C style in general, though the author didn’t declare it as such.
sagacity•4h ago
ginko•55m ago
And template for but I assume that's like inline for like in zig.
CamouflagedKiwi•26m ago
Not familiar with Zig but AFAICT `inline for` is about instructing the compiler to unroll the loop, whereas `template for` means it can be evaluated at compile time and each loop iteration can have a different type for the iteration variable. It's a bit crazy but necessary for reflection to work usefully in the way the language sets it up.
ginko•18m ago
https://ziglang.org/documentation/master/#inline-for
randusername•31m ago