I started reading about reflection in C++20 and got quite confused. What is the current state of it, i.e. how much can we use as of now?
I've found reflection TS - but even the examples on this website fail to compile (on GCC11 with C++20) because the compiler cannot find "#include <experimental/reflect>"... So it's not exactly in the GCC?
So my question is: can we use anything of reflection now, without waiting for C++23? By 'anything' I mean for example querying the compiler for list of class members, names of enums etc? And by 'use' I mean in production code, not just for playing around.
Here is a link to Andrei Alexandrescu'
talk on reflection at CppCon 2022, which addresses your main question: the proposals for reflection are still in the pipeline. Assuming the three-year timeline for the ISO committee to finalize the next iteration of c++ (c++26) and then sufficient time for compilers to implement and support the approved features, we are looking at least half a decade before reflection (and insertion) appears under the std banner inside gcc, clang/llvm, msvc, etc.
Since half a decade is a long time for reflection under the hood, you could achieve something similar on the surface. For example, you can just build a minimal c++20 script language for your small application to pry open the executable (not unlike objdump) and then you have the fabled interpreted environment (not unlike python) with reflection, insertion and the whole gamut of introspection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With