Description
In section 5.6 Coproduct, there is the first mention of C++ union and how they are not tagged unions, and later it mentions boost::variant
. However, we've had std::variant
for a while now, so it might be a good idea to mention that.
Later on, when talking about sum types (6.2), it says:
You will rarely see
union
used as a sum type in C++ because of severe limitations [...] You can't even put astd::string
into a union.
Though indeed I variants are definitely not as common as inheritance, this paragraphs ignores the fact that you can easily define a sum type with std::variant
in C++17 and up, and you can put std::string
in it as well.
If anything, I would say something like:
You rarely see unions in C++ because of the lack of pattern matching support in the language.
Anyway, it's not a big deal but it could be misleading for someone who isn't familiar with C++.
Activity