3 ms·
Sort of. The closest thing in C++ would be concepts. That is, even using traits in this way is the minority case; they're more usually used for monomorphized, s
by steveklabnik 10y ago
Sort of. The closest thing in C++ would be concepts. That is, even using traits in this way is the minority case; they're more usually used for monomorphized, statically dispatched code.
But, given the case where you want dynamic dispatch, then in a sense, they are, yes.
- lacampbell 10y agoRight. I suppose in Rust you generally use variants and pattern matching when dynamic dispatching is required.
- steveklabnik 10y agoYou could, but that requires that you know all of the variants ahead of time. The advantage of trait objects is that you don't have to. It really just depends on what exactly you're trying to do.