C++ Logo

std-proposals

Advanced search

Re: std::variant - going from Alternative& to the enclosing variant&

From: Victor Khomenko <victor.khomenko_at_[hidden]>
Date: Tue, 15 Sep 2020 16:02:26 +0000
> For what it's worth: the implementation of a std::variant provides indexed
> visitation internally - that is, it passes the index of the variant member into
> internal visitors. Exposing such functionality to users seems like a fairly easy
> stretch of imagination.

That's useful to know, but the argument is based on a particular implementation, so may be rejected by the Committee. I think this argument can be strengthened by noting that:
  * variant is allowed several occurrences of the same type;
  * if that happens, there must be a good reason for that (as opposed to uniquifying the type list);
  * so it's likely one may need to distinguish between occurrences of the same type within a visitor.
Then this variant implementation is an example of why it's useful.

Received on 2020-09-15 11:02:32