Skip to content

Add tutorials for type-erasure, reflection and vanishing-this#96

Open
jbcoe wants to merge 2 commits into
mainfrom
tutorials
Open

Add tutorials for type-erasure, reflection and vanishing-this#96
jbcoe wants to merge 2 commits into
mainfrom
tutorials

Conversation

@jbcoe

@jbcoe jbcoe commented Jul 22, 2026

Copy link
Copy Markdown
Owner

I'm not entirely sure that these tutorials are necessary.

The act of writing them was useful and perhaps they will be useful to readers of the (increasingly novel and technical) code in #95.

@jbcoe
jbcoe requested a review from Twon July 22, 2026 22:18
@jbcoe
jbcoe marked this pull request as ready for review July 22, 2026 22:18
@Twon

Twon commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

I think these are great, first 2 down and working through the 3rd now, but these are definitely useful (I'm learning reflection from the 3rd).

Perhaps the files could be renamed with a number indicating the order of the tutorials?

  1. 1_type_erasure.cc
  2. 2_vanishing_this_pointer
  3. 3_reflection.cc

The pedant in me finds it odd to start in the middle, go down and then go up in the file view in VSCode.

Comment thread tutorials/reflection.cc
int z = 0;
};

consteval std::vector<std::meta::info> data_members_of(std::meta::info type) {

@Twon Twon Jul 23, 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.

May as well just use std::vector's range constructor

Suggested change
consteval std::vector<std::meta::info> data_members_of(std::meta::info type) {
consteval std::vector<std::meta::info> data_members_of(std::meta::info type) {
return std::meta::nonstatic_data_members_of(
type, std::meta::access_context::current());
}

Comment thread tutorials/reflection.cc
int payload = 0;
};

consteval std::vector<std::meta::info> member_functions_of(

@Twon Twon Jul 23, 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.

consteval std::vector<std::meta::info> member_functions_of(std::meta::info type) {
    // is_function alone would also match Widget's implicit special
    // members (default constructor, destructor, ...);
    // is_special_member_function excludes those, leaving just the
    // two ordinary methods below.
    auto const is_member_function = [](std::meta::info member) {
        return std::meta::is_function(member) && !std::meta::is_special_member_function(member);
    };

    return std::meta::members_of(type, std::meta::access_context::current()) |
           std::ranges::views::filter(is_member_function) |
           std::ranges::to<std::vector<std::meta::info>>();
}

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