Hacker News new | ask | show | jobs
by spacechild1 245 days ago
> I will boldly state that std::variant makes all code worse and it is always better to not use it.

And I will boldly state that your comment is again completely hyperbolic.

> std::variant is fundamentally broken because it uses types as its discriminant.

In my experience, the typical use case for std::variant is static polymorphism. For this purpose it works just fine because the type is the discriminator.

Another popular use case is tagged unions for non-POD types. In this case, you probably access the active member with std::get. This even works with duplicate types, if you access by index.

Would proper sum types and pattern matching be nice? Of course! But does this mean that std::variant is fundamentally broken? I don't think so.