Boost logo

Boost :

From: Thomas Witt (witt_at_[hidden])
Date: 2002-02-01 06:16:26


I think there are a few problems with the code as it is right now.

1. The use of %= is non-portable as the result for negative n (I think we can
reasonably assume the size being positive) is implementation defined.
Furthermore behaviour for m_cycle_size == 0 is undefined.

    template <typename CycleIterator>
    void advance( CycleIterator& x, difference_type n ) {
        n %= m_cycle_size;

2. The different implementations for advance depending on the iterator
category are unneeded. In my opinion advance should only be provided for
random access iterators, the only exception beinng an conversion adaptor that
explicitly strives to raise the iterator category. The stdlib approach as I
understand it is: provide only those functions that are reasonably efficient.
Boost should take the same approach as users are used to it.

If advance for other then random access iterators is removed the size ctor
parameter can be removed. To me specifying a range and its size is error
prone and should be avoided.

3. The policies object stores base_iterators. As a result
cyclic_iterator<iterator> and cyclic_iterator<const_iterator> are not
interoperable (see msg #24803). Users will not expect it to be so. This is a
result of the current iterator_adaptor design and cannot be avoided at no

I've uploaded cyclic_arry.hpp in dir other. It internally uses a
cyclic_iterator implementation. Though this code might not be perfect it
tries to avoid the problems mentioned above. To make cyclic_iterator
interoperable it always stores non const iterators in the policies object.
This is no problem with cyclic_array but may well be a problem for other uses.


Dipl.-Ing. Thomas Witt
Institut fuer Verkehrswesen, Eisenbahnbau und -betrieb, Universitaet Hannover
voice: +49(0) 511 762 - 4273, fax: +49(0) 511 762-3001

Boost list run by bdawes at, gregod at, cpdaniel at, john at