Boost logo

Boost :

Subject: Re: [boost] Ternary logic programming (was: Re: [variant] Maintainer)
From: Niall Douglas (s_sourceforge_at_[hidden])
Date: 2015-07-02 06:19:02


On 2 Jul 2015 at 9:36, Joseph Van Riper wrote:

> (Sorry so many snips, but I wanted to focus on something specific).
>
> It probably isn't elegant, but maybe we could explore something like:
>
> tribool t;
>
> boost::if_( t,
> [&]( /*true condition's code*/),
> [&](/*false conditions code*/),
> [&](/* indeterminate conditions code*/)
> );
>
> Although there has to be a better way to clean it up... maybe with tagging
> the arguments or something.

Lightweight monad already has that:

    monad<std::string> a("niall");
    // Does bind work with chains of value, error, exception and
empty?
    auto x(
      a >> [ec](std::string){return ec;}
>> [](std::error_code){return std::make_exception_ptr(5);}
>> [](std::exception_ptr){return;}
>> [](monad<std::string>::empty_type){return
std::string("douglas");}
    );
    BOOST_CHECK(x.get()=="douglas");

    // Does monad type permutation from bind work?
    auto y(
      a >> [ec](std::string) -> monad<int> {return ec;}
>> [](std::error_code){return std::make_exception_ptr(5);}
>> [](std::exception_ptr){return;}
>> [](monad<int>::empty_type){return 5;}
    );
    BOOST_CHECK(y.get()==5);

Niall

-- 
ned Productions Limited Consulting
http://www.nedproductions.biz/ 
http://ie.linkedin.com/in/nialldouglas/



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