Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2000-06-11 23:07:54

----- Original Message -----
From: <jsiek_at_[hidden]>
> I mean would it be possible to remove the operator++, --, +=, and -=
> from the reverse_iterator class and have it inherit those operators.
> It seems to me all I should really have to do is write out the policy
> functions and have the rest taken care of by the wrap_iterator.

Given that *all* the inherited friend functions are supposed to be
instantiated, I don't think this approach will work for conforming
compilers. Even if it *would* work, I don't see what we'd gain by doing

> template <class Iterator, class NonconstIterator = Iterator, class Traits
= std::iterator_traits<Iterator> >
> class reverse_iterator
> [...]
> Self& operator++() {
> Base::operator++();
> return *this;
> }
> [...]
> };

Having thought a bit more about reverse_iterator, I think a redesign is in
order. What is really needed is something more like this:

template <class Iterator, class ConstIterator = Iterator, class Traits =
std::iterator_traits<Iterator>, ConstTraits =
std::iterator_traits<ConstIterator> >
struct reverse_iterators
    typedef wrapped_iterator<Iterator, reverse_iterator_policies, Iterator,
Traits> iterator;
    typedef wrapped_iterator<ConstIterator, reverse_iterator_policies,
Iterator, ConstTraits> const_iterator;

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