Boost logo

Boost Users :

Subject: [Boost-users] [Iterator] filter_iterator over greedy?
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2013-01-07 08:49:40


Hi Folks,

Somewhat to my surprise this code, simply creating a filter_iterator,
evaluates the predicate
until an element satisfying the predicate is found. This seems wrong to me.
Shouldn't evaluation
of the predicate be delayed until the filter_iterator is dereferenced?

Thx, Rob.

#include <iostream>
#include <boost/range.hpp>
#include <boost/iterator/filter_iterator.hpp>

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

int main( )
{
    int array[] = { 0, 1 };

    boost::make_filter_iterator( predicate, boost::begin( array ),
boost::end( array ) );
}

> [Run]
predicate(0)

>



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