Boost logo

Boost Users :

Subject: Re: [Boost-users] [range] cannot use lambda predicate in adaptor with certain algorithms
From: Michel MORIN (mimomorin_at_[hidden])
Date: 2011-05-30 05:24:37


Nathan Ridge wrote:
> The following code illustrates the problem:
>
> #include <boost/range/algorithm/min_element.hpp>
> #include <boost/range/adaptor/filtered.hpp>
> int main()
> {
> int a[] = {1, 2, 3};
> auto is_odd = [](int i){ return i % 2 == 1; };
> boost::min_element(a | boost::adaptors::filtered(is_odd));
> }
>
> The errors are shown below.
>
> Is there a workaround for this?

Use oven::regular

    boost::min_element(a |
        boost::adaptors::filtered(pstade::oven::regular(is_odd))
    );

and here is the documentation of oven::regular
http://p-stade.sourceforge.net/oven/doc/html/oven/utilities.html#oven.utilities.regular

*** Note ***
`#define BOOST_RESULT_OF_USE_DECLTYPE` is necessary to compile
the above code. Without this, we have compiler errors (the oven library
seems not fully compatible with new compilers yet).

Regards,
Michel


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net