C++ type-erasure

Open-source C++ projects categorized as type-erasure

Top 8 C++ type-erasure Projects

type-erasure
  1. dyno

    Runtime polymorphism done right

    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.

  2. SaaSHub

    SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives

    SaaSHub logo
  3. function2

    Improved and configurable drop-in replacement to std::function that supports move only types, multiple overloads and more

  4. AnyAny

    C++17 library for comfortable and efficient dynamic polymorphism

  5. te

    C++17 Run-time Polymorphism (Type Erasure) library

  6. zoo

    Zoo library (by thecppzoo)

  7. cpp_traits

    rust-like traits (type erasure) on plain C++

  8. polytail

    Rust-like trait-based polymorphism for C++

  9. woid

    C++ type erasure and non-intrusive polymorphism.

    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...

NOTE: The open source projects on this list are ordered by number of github stars. The number of mentions indicates repo mentiontions in the last 12 Months or since we started tracking (Dec 2020).

C++ type-erasure discussion

Log in or Post with

C++ type-erasure related posts

  • Show HN: Woid – 3x Faster Runtime Polymorphism. C++23

    2 projects | news.ycombinator.com | 12 Jan 2026
  • C++ with no classes?

    1 project | dev.to | 9 Jul 2025
  • Simplest C++ Callback, from SumatraPDF

    3 projects | news.ycombinator.com | 15 Jun 2025
  • DynaMix 2.0.0 Released

    8 projects | /r/cpp | 13 Apr 2023
  • rust-like traits on plain C++ with short macro (type erasure actually)

    5 projects | /r/cpp | 7 Apr 2023
  • C++ Polymorphism Without Inheritance Using Glaze

    8 projects | /r/cpp | 12 Jan 2023
  • Potential C++ extension for type erasure as a language feature

    2 projects | /r/cpp | 10 Nov 2022
  • A note from our sponsor - SaaSHub
    www.saashub.com | 14 Nov 2026
    SaaSHub helps you find the best software and product alternatives Learn more →

Index

What are some of the best open-source type-erasure projects in C++? This list will help you:

# Project Stars
1 dyno 1,043
2 function2 607
3 AnyAny 511
4 te 498
5 zoo 139
6 cpp_traits 16
7 polytail 9
8 woid 7

Sponsored
SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com

Did you know that C++ is
the 7th most popular programming language
based on number of references?