
christopher diggins wrote:
Well all of this talk of matricies, and what not got me thinking that perhaps we should get back to basics and introduce stride iterators into Boost which properly model the Random Access Iterator concept (unless they are already existant somewhere and I simplty overlooked them :-p ) I would suggest that we introduce a mini-library simply for stride iterators (and k-stride iterators, where the stride factor is a compile-time constant.) Any interest in seeing the following stride iterators submitted to boost as a mini-library?
That would be useful, however your sample code has a problem with the end iterator. To iterate over every second element of a container that has an even length, the one-past-the-end stride-2 iterator is actually TWO past the end of the original container. Unless you have a special container where incrementing beyond the one-past-the-end is allowed, you need another solution (indexing?). [...]
template<class Iter_T> class stride_iter
[...]
template<class Iter_T, int Step_N> class kstride_iter
May I suggest struct VariableStride {}; template <class Iter_T, class Stride /* = VariableStride ? */ > class stride_iterator // ... use as stride_iterator<T, VariableStride> x; stride_iterator<T, boost::mpl::int_<2> > y; Cheers, Ian