Hacker News new | ask | show | jobs
by thestoicattack 2405 days ago
C++ has std::variant, but that's pretty new.
1 comments

My understanding is that's not really a sum type, though -- e.g., you couldn't use it to add a type to itself, only to add distinct types to each other.
No, you can add a type to itself (that is a pain in the ass though). You might be thinking of the fact that it may not hold a value (eg. if an exception is thrown while moving into it), but they made it as close to a sum as they could given the nature of C++.