Herb Sutter’s examples
- Show class members
- Parse JSON
- Cmdline Options Parser
- Ad-hoc polymorphism
- Reflection ad-hoc poly T
- “interface” metafunction
- “interface” now in EDG
Inbal Levi’s examples
Misc C++ Reflection examples
#include <iostream>
#include <meta>
template <typename E>
struct enum_item {
std::string_view name;
E value;
};
template <typename E>
consteval auto get_enum_data() {
std::array<enum_item<E>, std::meta::enumerators_of(^^E).size()> result;
int k = 0;
for (auto mem : std::meta::enumerators_of(^^E))
result[k++] = enum_item<E>{std::meta::identifier_of(mem),
std::meta::extract<E>(mem)};
return result;
}
enum class Color { Red, Blue, Green };
int main() {
std::cout << "members of " << std::meta::identifier_of(^^Color) << '\n';
for (auto x : get_enum_data<Color>()) {
std::cout << " " << x.name << " = " << (long)x.value << '\n';
}
}
- Simple example
- Online JSON example - clang experimental P2996
- Initial JSON example - clang experimental P2996
- EDG GNU Experimental Reflection
References
- Reflection: C++’s Decade-Defining Rocket Engine - Herb Sutter - CppCon 2025
- An Introduction to the new C++ 26 “Reflection” Feature - Inbal Levi - CppCon 2025, slides
- C++ 26 Reflections
- the hidden compile-time cost of C++26 reflection
- C++ Paths and Perspectives, Daveed Vandevoorde / Regularizing C++ for Reflection
- Discover C++26’s compile-time reflection
- https://github.com/lemire/Code-used-on-Daniel-Lemire-s-blog/blob/master/2025/06/21/sqlinsert.h
- Barry’s C++ Blog: Reflecting JSON into C++ Objects
- C++26 Reflections adventures & compile time UML