Skipping iterator

ltjax picture ltjax · Apr 16, 2011 · Viewed 9.1k times · Source

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.

Answer

Nathan Phillips picture Nathan Phillips · Sep 24, 2014

I think you want boost::adaptors::strided