With a random access iterator, you can change the stride length by simply doing iter+=n and then using < container.end() instead of != container.end() as the loop ending condition:
#include <iostream>
#include <vector>
int main(int argc, char *argv[])
{
typedef std::vector<float> VectorType;
typedef VectorType::const_iterator IteratorType;
VectorType v;
for(unsigned int i = 0; i < 11; ++i)
{
v.push_back(i);
}
for(IteratorType iter = v.begin(); iter < v.end(); iter += 2)
{
std::cout << " " << *iter;
}
return 0;
}
However both += 2 and < iter.end() seem to be undefined for something like std::set. It seems reasonable to want traverse a set only visiting every other element (subsampling it), no? Is there another way to do this?