TL;DR
A developer posted a Show HN showcasing a method for implementing type erasure with C++26 reflection. The approach aims to improve code clarity and flexibility in C++ programming. The development is experimental and available for testing on Compiler Explorer.
A developer has shared a demonstration on Show HN illustrating how to implement type erasure using upcoming C++26 reflection features. This approach aims to simplify code and enhance flexibility in C++ programming, attracting attention from developers interested in modern C++ capabilities.
The project, showcased on Show HN, leverages C++26 reflection—a proposed feature set for the next C++ standard—to enable more elegant type erasure. The developer has provided a working example on Compiler Explorer for testing and review. The code demonstrates how reflection can be used to automate and simplify the process of hiding concrete types behind a common interface, a technique historically achieved through complex templates and manual boilerplate.
This demonstration is still experimental, and it is not yet clear whether C++26 reflection will become part of the standard or how widely it will be adopted. The developer has shared the source code openly, inviting feedback from the community and potential integration into larger projects.
Potential Impact of Reflection-Driven Type Erasure in C++
If adopted, this approach could significantly improve the clarity and maintainability of C++ code that relies on type erasure, such as in generic programming and polymorphic designs. It could reduce boilerplate and make code more adaptable to future changes, aligning with modern programming practices. However, as C++26 reflection is still in proposal stages, the actual impact depends on standardization progress and compiler support.

C++ All-in-One For Dummies
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
Evolution of Type Erasure and Reflection in C++
Type erasure has long been a core technique in C++, used to implement features like std::function and polymorphic containers, often involving complex template metaprogramming. Meanwhile, reflection has been a proposed feature for years, aimed at enabling introspection of types and members at compile time or runtime. C++20 introduced limited reflection capabilities, but full support remains a work in progress. The current demonstration explores how upcoming C++26 reflection could simplify and improve type erasure, building on recent proposals and experimental features.
“This demonstration shows how C++26 reflection can make type erasure more straightforward and elegant, potentially transforming how we write generic code in C++.”
— the developer behind the Show HN post
C++ reflection tutorials
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
Uncertainties Surrounding Standardization and Adoption
It is not yet confirmed whether C++26 reflection will be included in the final standard or how broadly compiler support will be. The current demonstration is experimental, and the approach may face compatibility or complexity challenges before wider adoption.
C++ type erasure library
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
Next Steps for Community Evaluation and Standardization
Community feedback on the demonstration will likely influence further development and refinement. Standardization efforts for C++26 reflection are ongoing, and future compiler implementations will determine how accessible this technique becomes for mainstream C++ development. Developers are encouraged to experiment and provide input to shape its evolution.

Introducing C++: The Easy Way to Start Learning Modern C++
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
Key Questions
What is type erasure in C++?
Type erasure is a technique that allows code to operate on objects of different types through a common interface, hiding the concrete type details. It is commonly used in features like std::function and polymorphic containers.
What role does C++26 reflection play in this demonstration?
The demonstration leverages C++26 reflection to automate and simplify the process of type erasure, reducing boilerplate code and improving clarity.
Is this approach ready for production use?
No, it is currently experimental and relies on features that are still under development and proposal stages. Its adoption depends on future standardization and compiler support.
How does this compare to traditional type erasure techniques?
Traditional techniques often involve complex templates and manual boilerplate, whereas this reflection-based approach aims to be more straightforward and maintainable, pending standardization.
When might this technique become widely available?
It depends on the progress of C++26 standardization and compiler implementation. If adopted, it could become accessible within the next few years, but no specific timeline is confirmed.
Source: hn