4 ms·
C++ you either use templates or classes and virtuals. In either case the caller doesn't get to decide.
by bfrog 9mo ago
C++ you either use templates or classes and virtuals. In either case the caller doesn't get to decide.
- Seattle3503 9mo agoInteresting, there isn't some way to have a template that is polymorphic over virtuals?
- Maxatar 9mo agoIn C++ you do it the other way around, have a single class that is polymorphic over templates. The name of this technique within C++ is type-erasure (that term means something else outside of C++). 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_typeerasure.html https://www.boost.org/doc/libs/latest/doc/html/boost_typeera...
- bfrog 9mo agoIt's neat this is a thing I guess, but I agree it looks fairly clumsy compared to the Rust answer.