3 ms·
> That's exactly what a tagged union does. std::variant is a tagged union. Not exactly. std::variant is one particular type of a tagged union, where the only d
by JoshTriplett 9y ago
> That's exactly what a tagged union does. std::variant is a tagged union.
Not exactly. std::variant is one particular type of a tagged union, where the only discriminant is the type. You can also have a tagged union where the discriminant determines some semantic state, and multiple such states may store the same type of value. That's still a sum type, still a tagged union, and not something std::variant can do.
- clishem 9y agoThanks for the clarification. This article also helped. http://talesofcpp.fusionfenix.com/post-21/rant-on-the-stdexperimentalvariant-to-come http://talesofcpp.fusionfenix.com/post-21/rant-on-the-stdexp... In it's terminology, std::variant is a 'discriminated union' instead of a 'sum type'. Making std::variant the latter would also have had disadvantages it seems.