Reflection tutorial - #146
Conversation
78421b5 to
449e861
Compare
449e861 to
d88c703
Compare
dfc0352 to
1ee1e03
Compare
1ee1e03 to
7b843bd
Compare
4827585 to
4ac10e1
Compare
4ac10e1 to
3a2459f
Compare
ad90164 to
91ce8a7
Compare
RyanJK5
left a comment
There was a problem hiding this comment.
Really happy with how this came out. It keeps the relevant parts of reflection in clear focus.
| // We use `throw` inside a `consteval` block rather than `static_assert` | ||
| // or `EXPECT_*`: `static_assert` needs `members` to independently be a | ||
| // constant expression, and `EXPECT_*`'s comparison helpers aren't | ||
| // `constexpr` functions. |
There was a problem hiding this comment.
This could probably do with a one-sentence explanation of what a consteval block is.
| TEST(TutorialsReflection, Substitute) { | ||
| // `substitute(^^Template, {args...})` instantiates a template from infos; | ||
| // `reflect_constant` turns an ordinary value into an info usable as a | ||
| // non-type template argument. | ||
| // clang-format off | ||
| constexpr std::meta::info array_info = | ||
| substitute(^^std::array, {^^double, std::meta::reflect_constant(3)}); | ||
| // clang-format on | ||
|
|
||
| static_assert(std::is_same_v<typename[:array_info:], std::array<double, 3>>); | ||
| } |
There was a problem hiding this comment.
I think this could benefit from a comment explaining the use case of substitute - when you want to use a reflection in a consteval context even though it itself is not a constant expression.
For me, at least, I found the distinction between constant expressions and consteval to be one of the more difficult topics when first learning reflection.
There was a problem hiding this comment.
@RyanJK5 If you have suggested wording, that would be awesome. I think there are still some gaps in my understanding around this.
a3a67cc to
a778e0b
Compare
a778e0b to
c478314
Compare
No description provided.