Boost logo

Boost :

Subject: Re: [boost] Variant and visitation (was: [optional] Safe optional)
From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2014-11-18 17:52:27


On 18 Nov 2014, at 22:59, Antony Polukhin <antoshkka_at_[hidden]> wrote:

> 2014-11-19 0:40 GMT+03:00 Nevin Liber <nevin_at_[hidden]>:
>>
>> 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
> );

Alternatively, it could be done like this:

apply_visitor(variant_variable,
    [](int i) { std::cout << “int: “ << i; },
    [](float f) { std::cout << “float: “ << f; },
    otherwise([](auto v) { std::cout << “something: “ << v; });

I’ve recently written something very similar for boost::any, using runtime checks instead of course.

Sebastian


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