Boost logo

Boost :

From: jsiek_at_[hidden]
Date: 2000-06-12 21:47:30

David Abrahams writes:
> 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
> that.

Ok, here's another workaround idea: specialize the adaptor class based
on the iterator category and split the iterator functionality into
four iterator adaptor classes: trivial, forward, bidir, and random.

The following helper class would provide the def's for iterator and
const_iterator similar to what you proposed for reverse_iterators. The
iterator_adaptor classes would be specialized based on the category of

  template <class Iterator, class ConstIterator,
            class Traits = std::iterator_traits<Iterator>,
            class ConstTraits = std::iterator_traits<ConstIterator>,
            class Policies = default_iterator_policies>
  struct iterator_adaptor_helper
    typedef typename Traits::iterator_category Cat;
    typedef iterator_adaptor<Cat, Policies, Iterator, Traits,
      Iterator, Traits> iterator;
    typedef iterator_adaptor<Cat, Policies, ConstIterator, ConstTraits,
      Iterator, Traits> const_iterator;

So this won't work on VC++... well, I've got a workaround for that
too :)

So what's the advantage? Less code to write! Here's the new
implementation of reverse_iterators:

[... policy class ...]

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

I've uploaded the code as to the vault. All the
tests passed for g++ and KCC. I haven't tested the VC++
workaround yet.



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