On Mon, Jan 7, 2013 at 11:56 AM, Akira Takahashi <faithandbrave@gmail.com> wrote:
Hi Robert,

2013/1/7 Robert Jones <robertgbjones@gmail.com>
Hi Folks

This question is about using the OvenToBoost port, not currently part of Boost, but likely to be soon, I understand.

The code below evaluates the predicate for the first and second elements of the array. The evaluation of the
second element seems to me to be unnecessary and wrong, since the 'taken' adaptor knows the range is
ended after the first element is taken.

Thoughts?

Thx, Rob.

#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/adaptor/taken.hpp>
#include <boost/range/algorithm/for_each.hpp>
#include <iostream>

bool predicate( int i )
{
    std::cout << "predicate(" << i << ")" << std::endl;
    return true;
}

void doNothing( int ) { }

int main( )
{
    int array[ ] = { 0, 1, 2, 3, 4, 5 };

    for_each( array | boost::adaptors::filtered( predicate ) | boost::adaptors::taken( 1 ), doNothing );
}


`filtered` adaptor (boost::filter_iterator) is over call predicate for skip element.
This is boost::filter_iterator's specification. see: http://www.boost.org/doc/libs/1_52_0/libs/iterator/doc/filter_iterator.html

So it does... ok thx for that!

- Rob.