Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2003-12-08 14:31:14


I have a question regarding the filter_iterator which
is illustrated by the following small program:

#include <list>
#include <algorithm>
#include <boost/config.hpp>
#include <boost/compatibility/cpp_c_headers/cctype>
#include <boost/iterator/filter_iterator.hpp>

struct remove_whitespace_predicate
{
    char operator()(char t){
        return ! std::isspace(t);
    }
};

main(){
    typedef boost::filter_iterator<
        remove_whitespace_predicate,
        std::list<char>::const_iterator
> fi;

    std::list<char> clist;
    std::list<char> olist;
    std::copy(
        fi(clist.begin(), clist.end()),
        fi(), // ? what goes here
        std::back_inserter(olist)
    );
}

? what goes here ?
fi() doesn't work because base() != base(clist.end())
fi(clist.end()) crashes because the constructor for
fi dereferences its iterator argument which is not always
possible when the iterator corresponds to one more than
the end of the list.

Does anyone have something to recommend?

Robert Ramey


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