c++booststlboost-iterators

Skipping iterator


I have a sequence of values that I'd like to pass to a function that takes a (iterator begin, iterator end) pair. However, I only want every second element in the original sequence to be processed.

Is there a nice way using Standard-Lib/Boost to create an iterator facade that will allow me to pass in the original sequence? I figured something simple like this would already be in the boost iterators or range libraries, but I didn't find anything.

Or am I missing another completely obvious way to do this? Of course, I know I always have the option of copying the values to another sequence, but that's not what I want to do.

Edit: I know about filter_iterator, but that filters on values - it doesn't change the way the iteration advances.


Solution

  • I think you want boost::adaptors::strided