4 ms·
For most people "reflection" is a synonym to "runtime reflection". In contrast quotes and splices aren't reflection at all! The whole point about them is that
by still_grokking 4y ago
For most people "reflection" is a synonym to "runtime reflection".
In contrast quotes and splices aren't reflection at all! The whole point about them is that they're "black box". You (usually) can't "extract information" form a quote in a safe way (so it's the exact contrary to reflection). That's still something academia is trying to solve (even there are some proposals out)¹.
Where can I learn more about the C++ proposals to compare?
---
¹ https://dl.acm.org/doi/10.1145/3136000.3136005 https://dl.acm.org/doi/10.1145/3136000.3136005
¹ https://dl.acm.org/doi/10.1145/3158101 https://dl.acm.org/doi/10.1145/3158101
And the recent work that underlines the solution included in Scala 3:
¹ https://se.informatik.uni-tuebingen.de/publications/stucki21multistage.pdf https://se.informatik.uni-tuebingen.de/publications/stucki21...
- jcelerier 4y ago> For most people "reflection" is a synonym to "runtime reflection". I mean, that's just because many languages don't even have a compile-time so of course reflection can only be runtime. Every compiled language has at least some amount of extremely basic concept of compile-time reflection, e.g. sizeof in C for instance which yields a constant expression ; likewise, `if constexpr(std::is_same_v<T, some_other_type>) { ... }` which we can do since C++17 is very much in the domain of compile-time reflection. Here's the most recent paper: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1240r2.pdf https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p12... If you want this is a very good read: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0707r3.pdf https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p07... Finally, there is an implementation of the reflection TS: https://clementpirelli.wordpress.com/2021/12/08/cpp-reflection-ts-first-look/ https://clementpirelli.wordpress.com/2021/12/08/cpp-reflecti...
- still_grokking 4y agoOh, cool, direct links to the relevant papers! It's not always easy to find the relevant stuff in C++ land. Thanks a lot! I have to read this stuff first, but my gut feeling would still be that `constexpr` and such isn't reflection at all. The `sizeof` example seems more in this direction (because some expression gets actually inspected).
- jcelerier 4y agoi'm talking about "if constexpr", not "constexpr" ; "if constexpr" allows to make choices at compile time depending on properties of a variable and that is definitely what reflection is about. e.g. void f(auto x) { // common code path if constexpr(x is floating-point) { // code path 1 } else if constexpr(x is a string) { // code path 2 } // common code path }
- still_grokking 4y agoOh, I see. You're right. Thanks for the pointer.