C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: std::variant - going from Alternative& to the enclosing variant&
From: Victor Khomenko (victor.khomenko_at_[hidden])
Date: 2020-08-21 09:17:10


Thanks Ville,

>Use a lambda as a visitor and capture the variant in the lambda?

This won't work if the visitor requires very different processing for different Alternatives. My proposed workaround with a pointer in a visitor is similar to what you suggest, but your solution is restricted to the case when a single lambda can handle every alternative.

Victor.


> -----Original Message-----
> From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
> Sent: Friday, August 21, 2020 3:12 PM
> To: std-discussion_at_[hidden]
> Cc: Victor Khomenko <victor.khomenko_at_[hidden]>
> Subject: Re: [std-discussion] std::variant - going from Alternative& to the
> enclosing variant&
>
> âš  External sender. Take care when opening links or attachments. Do not
> provide your login details.
>
> On Fri, 21 Aug 2020 at 17:07, Victor Khomenko via Std-Discussion <std-
> discussion_at_[hidden]> wrote:
> >
> > Dear all,
> >
> > [I searched the list's archive but didn't find anything relevant.]
> >
> > Problem: How to change the value of a variant from within a visitor?
> Unfortunately, there is no straightforward way to do that, as the relevant
> operator()(Alternative&) of the visitor has no access to the enclosing
> std::variant.
>
> Use a lambda as a visitor and capture the variant in the lambda?


STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups