SaaSHub helps you find the best software and product alternatives Learn more →
Top 8 C++ type-erasure Projects
-
Project mention: Visualizing Rust's Vtables: How Dyn Trait Works in Memory | news.ycombinator.com | 2026-09-05
Ah. Dyno (https://github.com/ldionne/dyno) is good at this stuff. If you have types Base, Child1, Child2, you can just return a Dyno object that can be any of these, expressed as a tagged union and not a Box-equivalent, and then do regular vtable-based or otherwise polymorphic dispatch into the object. You can also arrange it so that if you have a Child3 that can't fit in the (Base, Child1, Child2) union, the Child3 can be heap-allocated and invoked transparently as well. It's open-world type erasure.
C++ is so freakishly powerful is that it can not only solve this problem, but it can solve it via a regular library and not a language extension.
-
SaaSHub
SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives
-
function2
Improved and configurable drop-in replacement to std::function that supports move only types, multiple overloads and more
-
-
-
-
-
-
Project mention: Show HN: Woid – 3x Faster Runtime Polymorphism. C++23 | news.ycombinator.com | 2026-01-12
Yes! https://github.com/akopich/woid/blob/main/bench/plots/FunBen...
Here I wrap std::less into different wrappers (and of them manage to do SBO) and feed it into std::sort. Unless std::sort does a ton of copies, this is predominantly down to function invocation, not instantiation/lifetime management.
There Woid is up to about 60% faster than std::function if it leverages the triviality of std::less. The advantage goes to 30% if don't optimize for trivial types. And either of the wrappers considered are much slower than just using the lambda directly (see the Id "wrapper") as the type-erased wrappers inhibit inlining.
I also do the same bench, but with a "big" less, so that std::function fails the SBO, there the gains go up to 2-2.5x. https://github.com/akopich/woid/blob/main/bench/plots/FunBen...
C++ type-erasure discussion
C++ type-erasure related posts
-
Show HN: Woid – 3x Faster Runtime Polymorphism. C++23
-
C++ with no classes?
-
Simplest C++ Callback, from SumatraPDF
-
DynaMix 2.0.0 Released
-
rust-like traits on plain C++ with short macro (type erasure actually)
-
C++ Polymorphism Without Inheritance Using Glaze
-
Potential C++ extension for type erasure as a language feature
-
A note from our sponsor - SaaSHub
www.saashub.com | 14 Nov 2026