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.
I agree with rlbond. Don't reinvent the wheel and use Boost::filter_iterator. If you don't want to have all boost libraries in your project, you may want to consider using boost.bcp to extract exactly the ones you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With