Interesting, there isn't some way to have a template that is polymorphic over virtuals?
Examples of type erasure in C++ are classes like std::function and std::any, and normally you need to implement the type erasure manually, but there are some library that can automate it to a degree, such as [1], but it's fairly clumsy.
[1] https://www.boost.org/doc/libs/latest/doc/html/boost_typeera...