Boost logo

Boost Users :

Subject: Re: [Boost-users] [range_ex] range adaptor and boost::lambda
From: Neil Groves (neil_at_[hidden])
Date: 2009-04-10 18:38:39


Hi,

On Fri, Apr 10, 2009 at 3:50 AM, 041021042 <041021042_at_[hidden]> wrote:

> Hi,
>
> I found another problem of range_ex. The following code still works well
> with the old version of range_ex (Dec 2008), and cause a compile error with
> the newest version.
>
>
The 'regression' was due to improved checking of the range concept
constraints within the boost::copy algorithm.

It appears that the filter_iterator assignment operator is invalid when used
with the lambda expression you have chosen. Since the filter_iterator
assignment is invalid it stands to reason that the range made from these
iterators also did not have a valid assignment operator and hence the range
library was correctly reporting that the result of the expression was not a
valid model of the SinglePassRangeConcept.

I suspect that the sample code provided was a stripped down example, but
just in case it wasn't I would like to point out that:
1. is_even can be implemented more efficiently as bool is_even(int x) {
return x & 1 == 0; }
2. The use of Boost.Lambda for the expression:
   boost::copy( input | filtered(bind(is_even, _1)),
       std::ostream_iterator<int>(std::cout, ",") );

Hence it can be replaced with:
   boost::copy( input | filtered(&is_even),
std::ostream_iterator<int>(std::cout, ",") );

I have uploaded a new version to the Boost Vault that relaxes the
SinglePassRangeConcept constraint to improve compatibility with
Boost.Lambda.

Thank you again for your report. I shall be making more tests for
compatibility with Boost.Lambda and making improvements where appropriate.

Best Wishes,
Neil Groves



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