I am passed an Iterator and I have to pass it on to another function — but filtered so that certain elements are skipped (it’s a range of pointers, and I want to filter out the NULL pointers).
I googled for ‘stl filter iterator‘ to see how to do this, and boost::filter_iterator came up.
That looks nice and I could use it, but could I do that with the good old STL as well? Without copying the elements into a new container, of course.
I guess I’d have to create another iterator class that provides the necessary begin(), end() etc functions and does the filtering? So I’d exactly have to reimplement the boost iterator_filter…?
You are correct; you would essentially be recreating the filter iterator yourself. My advice would be to use Boost’s filter_iterator. Boost has special status as c++’s most used external library; many c++ committee members have helped write libraries for boost. Its ubiquity essentially makes it almost-stl as is; there’s really no reason to reinvent the wheel here.