3 ms·
C++ has std::variant, but that's pretty new.
by thestoicattack 7y ago
C++ has std::variant, but that's pretty new.
- Sniffnoy 7y agoMy 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.
- edflsafoiewq 7y agoNo, 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++.