Skip to content

Acknowledge std::variantΒ #268

Open
Open
@elshize

Description

@elshize

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 a std::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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions