C++ Logo

std-discussion

Advanced search

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

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Fri, 21 Aug 2020 17:47:05 +0300
On Fri, 21 Aug 2020 at 17:33, Victor Khomenko
<victor.khomenko_at_[hidden]> wrote:
> 3. Solution with a new visit-function that provides the variant itself as a parameter to the visitor seems acceptable - but looks more complicated than what I proposed?

I don't think so. The magic-function you suggest would seemingly need
to be told what kind of a variant to convert to.
In the approach I suggest, that's your parameter type. The error
possibility of getting the variant type wrong is not there;
the type and value of the variant is statically correct, as opposed to
possibly being incorrect at run time.

Received on 2020-08-21 09:50:43