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 04:50:33


Hi Nate,

Nathan Ridge wrote:
> I get errors related to lambdas not being default-constructible or copy-assignable
> when using a lambda as a predicate with certain adaptors (e.g. filtered) and
> certain algorithms (e.g. min_element).
>
> 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?

I don't have any workarounds :-(
but I'd like to make a comment.

I think filter_iterator and transform_iterator should use boost::optional to
cope with this kind of problems. For transform_iterator, there's a trac ticket
https://svn.boost.org/trac/boost/ticket/4189
Unfortunately there is no reaction on this ticket.

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