Tech News
← Back to articles

Type-based vs. Value-based Reflection

read original related products more articles

Type-based vs Value-based Reflection

Frequently, whenever the topic of Reflection comes up, I see a lot of complains specifically about the new syntax being added to support Reflection in C++26. I’ve always thought of that as being largely driven by unfamiliarity — this syntax is new, unfamiliar, and thus bad. I thought I’d take a different tactic in this post: let’s take a problem that can only be solved with Reflection and compare what the solution would look like between:

the C++26 value-based model

the Reflection Technical Specification (TS)’s type-based model

Don’t worry if you’re not familiar with the Reflection TS, I’ll go over it in some detail shortly.

But first, today’s problem. C++20 introduced the concept of structural type. These are the kinds of types that you can use as non-type constant template parameters. The definition of structural type is:

A structural type is one of the following: a scalar type, or

an lvalue reference type, or

a literal class type with the following properties: all base classes and non-static data members are public and non-mutable and the types of all base classes and non-static data members are structural types or (possibly multidimensional) arrays thereof.

... continue reading