Power of C++26 Reflection: Strong (opaque) type definitions -- r/cpp
Inspired by a similar previous thread showcasing cool uses for C++26 reflection.
Power of C++26 Reflection: Strong (opaque) type definitions
From the article:
With reflection, you can easily create "opaque" type definitions, i.e "strong types". It works by having an inner value stored, and wrapping over all public member functions.
Note: I am using queue_injection { ... } with the EDG experimental reflection, which afaik wasn't actually integrated into the C++26 standard, but without it you would simply need two build stages for codegen. This is also just a proof of concept, some features aren't fully developed (e.g aggregate initialization)
struct Item { /* ... */ }; // name, price as methods struct FoodItem; struct BookItem; struct MovieItem; consteval { make_strong_typedef(^^FoodItem, ^^Item); make_strong_typedef(^^BookItem, ^^Item); make_strong_typedef(^^MovieItem, ^^Item); } // Fully distinct types void display(FoodItem &i) { std::cout << "Food: " << i.name() << ", " << i.price() << std::endl; } void display(BookItem &i) { std::cout << "Book: " << i.name() << ", " << i.price() << std::endl; } int main() { FoodItem fi("apple", 10); // works if Item constructor isn't marked explicit FoodItem fi_conversion(Item{"chocolate", 5}); // otherwise BookItem bi("the art of war", 20); MovieItem mi("interstellar", 25); display(fi); display(bi); // display(Item{"hello", 1}); // incorrect, missing display(Item&) function // display(mi); // incorrect, missing display(MovieItem&) function }

Registration is now open for CppCon 2026! The conference starts on September 12 and will be held
Registration is now open for CppCon 2026! The conference starts on September 12 and will be held
Registration is now open for CppCon 2026! The conference starts on September 12 and will be held
In algorithmic trading, the Python-vs-C++ debate is usually framed as flexibility versus speed — rapid strategy development on one side, ultra-low-latency execution on the other. But with C++26 reflection, that trade-off starts to disappear, making it possible to generate Python bindings automatically while keeping the core logic running at native C++ performance.
Registration is now open for CppCon 2026! The conference starts on September 12 and will be held