C++ Logo

std-proposals

Advanced search

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

From: Victor Khomenko <victor.khomenko_at_[hidden]>
Date: Fri, 11 Sep 2020 15:31:00 +0000
> Nice ideas! They still require more typing, namely an extra parameter and an
> extra line of code to recover the alternative. How about going a step further,
> and capture the variant inside the tag, and make the tag convertible to
> Alternative&, e.g.:
>
> void operator(std::variant_tag<1> t) {
> do_something_with_variant(t.get_variant());
> do_something_with_alternative(t); // t is converted to Alternative& or
> const Alternative&
> do_something_else_with_alternative(move(t)); // converted to
> Alternative&& }

And yet another step: the implementation of std::visit could be amended so that if the visitor accepts arguments of type variant_tag<> rather than alternative types, then it recognises and handles this, so that there is no need to create another visitation function?


Received on 2020-09-11 10:34:34