Boost logo

Boost :

Subject: Re: [boost] Variant and visitation (was: [optional] Safe optional)
From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2014-11-18 16:59:23


2014-11-19 0:40 GMT+03:00 Nevin Liber <nevin_at_[hidden]>:

> On 18 November 2014 15:02, Matt Calabrese <rivorus_at_[hidden]> wrote:
>
> >
> > > > For a while I assumed exactly that, but he actually specifically
> voiced
> > > > that he does not like visitation on variant and thinks of it as a
> hack.
> > > > It's sad :/
> > > >
> > >
> > > FWIW: I think he is (a) correct, but (b) we have nothing better to
> > replace
> > > it, so we still need it.
> > >
> >
> > We should really start a thread about this. I'm very curious to see an
> > actual objective rationale both for why visitation over a closed set of
> > types known at compile time is in any way a "hack,"
>
>
> It's the inversion of control that people just don't like.
>

As a guy, who's been keeping an eye on Boost.Variant for last two years, I
was planning to add support for generalized lambdas as a visitors for
variant:

apply_visitor(
    [](auto v){ std::cout << v; },
    variant_variable
);

This looks more friendly that defining a visitor structure, so maybe users
will like it better.

Here's another example

auto sum = apply_visitor(
    [](auto v1, auto v2) { return v1 + v2; },
    variant_variable1,
    variant_variable2
);

> > along with a realistic
> > alternative.
>
>
> As I already said, I don't know of one, and having it is better than not
> having it.
>
> The discussion in Urbana on n4218
> <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4218.pdf>
> (variant), which didn't propose visitation, basically amounted to we don't
> like visitation but we need it unless something better comes along.
>

Hmmm, I see that paper for the first time. I like it but there are a few
issues that must be clarified and fixed. Was there a discussion of that
paper at std-proposals?

-- 
Best regards,
Antony Polukhin

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk