Boost logo

Boost :

From: John R. Bandela (jbandela_at_[hidden])
Date: 2003-07-01 19:34:33


I was playing with the new iterator adapters in the sandbox. As I was
looking at filter_iterator, I found that it allows user code to increment it
like a random access iterator. Here is an example that compiled on VC 7.1

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

struct even
{
    bool operator()(int x) const
    {
        return x%2 == 0;
    }
};
int main( int argc, char* argv[] )
{
    int test[] = {1,2,3,4,5,6,7,8,9,10};

    typedef boost::filter_iterator<even,int*> filter_iter;

    filter_iter f(test,test+10);
    std::cout << "Correct filter results\n";

std::copy(f,filter_iter(test+10,test+10),std::ostream_iterator<int>(std::cou
t,"\n"));
    std::cout << "\nIncorrect filter results\n";

std::copy(f+1,filter_iter(test+10,test+10),std::ostream_iterator<int>(std::c
out,"\n"));

}

Should filter_iterator use iterator_facade as its base instead of
iterator_adapter? It seems the iterator_adapter is incorrectly implementing
advance.

Regards,

John Bandela

PS: I don't know if this is the place to ask, but I have updated tokenizer
to the new iterator adapters. Is there some place it should be placed
pending release of the new iterator_adapters?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk