Skip to content

Reflection tutorial - #146

Open
jbcoe wants to merge 5 commits into
mainfrom
reflection-tutorial
Open

Reflection tutorial#146
jbcoe wants to merge 5 commits into
mainfrom
reflection-tutorial

Conversation

@jbcoe

@jbcoe jbcoe commented Aug 14, 2026

Copy link
Copy Markdown
Owner

No description provided.

@jbcoe
jbcoe changed the base branch from main to vanishing-this-tutorial August 14, 2026 17:49
@jbcoe
jbcoe force-pushed the reflection-tutorial branch 2 times, most recently from 78421b5 to 449e861 Compare August 17, 2026 22:47
@jbcoe
jbcoe force-pushed the reflection-tutorial branch from 449e861 to d88c703 Compare August 17, 2026 23:44
Base automatically changed from vanishing-this-tutorial to main August 18, 2026 07:47
@jbcoe
jbcoe force-pushed the reflection-tutorial branch 2 times, most recently from dfc0352 to 1ee1e03 Compare August 18, 2026 07:48
@jbcoe
jbcoe changed the base branch from main to cpp26-infra August 18, 2026 08:27
@jbcoe
jbcoe force-pushed the reflection-tutorial branch from 1ee1e03 to 7b843bd Compare August 18, 2026 08:28
@jbcoe
jbcoe marked this pull request as ready for review August 18, 2026 08:37
@jbcoe
jbcoe force-pushed the reflection-tutorial branch from 4827585 to 4ac10e1 Compare August 18, 2026 12:08
@jbcoe
jbcoe requested a review from RyanJK5 August 18, 2026 16:57
@jbcoe
jbcoe force-pushed the reflection-tutorial branch from 4ac10e1 to 3a2459f Compare August 18, 2026 21:18
@jbcoe
jbcoe force-pushed the reflection-tutorial branch 5 times, most recently from ad90164 to 91ce8a7 Compare August 18, 2026 22:36

@RyanJK5 RyanJK5 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really happy with how this came out. It keeps the relevant parts of reflection in clear focus.

Comment thread tutorials/reflection.cc
Comment on lines +82 to +85
// 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.

@RyanJK5 RyanJK5 Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably do with a one-sentence explanation of what a consteval block is.

Comment thread tutorials/reflection.cc
Comment thread tutorials/reflection.cc
Comment on lines +280 to +290
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>>);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RyanJK5 If you have suggested wording, that would be awesome. I think there are still some gaps in my understanding around this.

Comment thread tutorials/reflection.cc
@jbcoe
jbcoe force-pushed the reflection-tutorial branch 2 times, most recently from a3a67cc to a778e0b Compare August 22, 2026 14:29
Base automatically changed from cpp26-infra to main August 22, 2026 14:32
@jbcoe
jbcoe force-pushed the reflection-tutorial branch from a778e0b to c478314 Compare August 22, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants