Boost logo

Boost :

From: christopher diggins (cdiggins_at_[hidden])
Date: 2005-06-03 13:47:08


----- Original Message -----
From: "Ian McCulloch" <ianmcc_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Friday, June 03, 2005 2:09 PM
Subject: [boost] Re: stride iterators and matricies

> 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?).

Would indexing not lead to a similar problem? I would have thought the only
way out is to pass a size parameter to the iterator. Do any iterators exist
which do not allow incrementing past one past the end?

How about if == was defined as :

friend bool operator==(const self& x, const self& y) {
  return (y - x) < step;
}

and similarly for operator<() ?

> [...]
>
>> 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;

Interesting idea, and more elegant. I would not do it that way, but I would
be willing to be it would be more popular to implement as you suggest.

-Christopher Diggins


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk