Boost logo

Boost :

Subject: Re: [boost] Variant and visitation (was: [optional] Safe optional)
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2014-11-18 18:06:07


Le 18/11/14 23:52, Sebastian Redl a écrit :
> 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.
>
I have been playing with make_overload/match (See
https://github.com/viboes/tags/blob/master/test/any/include_pass.cpp#L259)

     boost::any a = 2;
     boost::any b = std::string("2");
functional::match_all<void>(std::make_tuple(select<types<int,
std::string>>(a), select<types<int, std::string>>(b)),
         [](int i, int j )
         {
           BOOST_TEST(false);
         },
         [](auto &&i, auto &&j )
         {
         },
         [](...)
         {
           BOOST_TEST(false);
         }
     );

Best,
Vicente


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