Date: Fri, 21 Aug 2020 14:17:10 +0000
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]om>
> Sent: Friday, August 21, 2020 3:12 PM
> To: std-discussion_at_lists.isocpp.org
> Cc: Victor Khomenko <victor.khomenko_at_newcastle.ac.uk>
> 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]p.org> 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?
>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]om>
> Sent: Friday, August 21, 2020 3:12 PM
> To: std-discussion_at_lists.isocpp.org
> Cc: Victor Khomenko <victor.khomenko_at_newcastle.ac.uk>
> 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]p.org> 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?
Received on 2020-08-21 09:20:38