Question Details

No question body available.

Tags

c++ c++26 static-reflection

Answers (1)

Accepted Answer Available
Accepted Answer
February 10, 2026 Score: 4 Rep: 313,253 Quality: Expert Completeness: 80%

There simply is no way in C++26 reflection to generate member functions.

The only C++26 code generation mechanism is defineaggregate(cls, specs), which only lets you complete the class represented by cls with a (possibly-empty) sequence of non-static data members.

It's an open question as to whether (and how) this will be possible in C++29.


That said, you can get the information you want. You just can't use it to generate anything:

  • returntypeof(^^MyBase::f) will give you ^^void
  • parametersof(^^MyBase::f) will give you a vector of reflections representing the parameters, so
  • parametersof(^^MyBase::f) | views::transform(meta::typeof) will give you the sequence {^^int, ^^acme::arg}

As @T.C. points out, cause I haven't internalized this yet — parametersof(r) gives you:

r reprents... result
a function F reflections representing the parameters of F
a function type FT reflections representing the types of the parameters of FT

Here, typeof(^^MyBase::f) is a reflection representing the type void(int, acme::arg), so parametersof(typeof(^^MyBase::f)) is the vector {^^int, ^^acme::arg} directly (avoiding the need for the views::transform).

Note that returntypeof(^^MyBase::f) and returntypeof(type_of(^^MyBase::f)) is the same — both ^^void.