For small to small-medium size datasets std::variant (aka type-safe union) is a neat trick. For that kind of datasets combining std::variant with std::visit can be a good substitute for runtime polymorphism. But for large datasets std::variant has two main problems:
- There is extra code that compilers/users must insert to figure out the type of each item inside std::variant in conjunction with std::visit and what to do with it
- Size of std::variant is the size of its largest member. So, you could be wasting significant memory space