diff --git a/iterator_adaptors.htm b/iterator_adaptors.htm index 72b5bff..976870a 100644 --- a/iterator_adaptors.htm +++ b/iterator_adaptors.htm @@ -32,9 +32,25 @@
  • Header Dave Abrahams started the library, applying policies class technique + "../../more/generic_programming.html#policy">policy class technique and handling const/non-const iterator interactions. He also contributed the indirect_ and reverse_ iterator generators, and expanded counting_iterator_generator to - cover all incrementable types.
    + cover all incrementable types. He edited most of the documentation, + sometimes heavily.
    Jeremy Siek contributed the transform iterator adaptor, the integer-only version of const and non-const iterators. -

    Synopsis

    +

    iterator_adaptor is declared like this:

     template <class Base, class Policies, 
         class Value = typename std::iterator_traits<Base>::value_type,
         class Reference = ...(see below),
         class Pointer = ...(see below),
         class Category = typename std::iterator_traits<Base>::iterator_category,
    -    class Distance = typename std::iterator_traits<Base>::difference_type
    -         >
    +    class Distance = typename std::iterator_traits<Base>::difference_type>
     struct iterator_adaptor;
    -{
    -    typedef Distance difference_type;
    -    typedef typename boost::remove_const<Value>::type value_type;
    -    typedef Pointer pointer;
    -    typedef Reference reference;
    -    typedef Category iterator_category;
    -    typedef Base base_type;
    -    typedef Policies policies_type;
    -
    -    iterator_adaptor();
    -    iterator_adaptor(const Base&, const Policies& = Policies());
    -
    -    base_type base() const;
    -
    -    template <class B, class V, class R, class P>
    -    iterator_adaptor (
    -        const iterator_adaptor<B,Policies,V,R,P,Category,Distance>&);
    -
    -    reference operator*() const;
    -    operator_arrow_result_type operator->() const; [2]
    -    value_type operator[](difference_type n) const;
    -
    -    iterator_adaptor& operator++();
    -    iterator_adaptor& operator++(int);
    -    iterator_adaptor& operator--();
    -    iterator_adaptor& operator--(int);
    -
    -    iterator_adaptor& operator+=(difference_type n);
    -    iterator_adaptor& operator-=(difference_type n);
    -
    -    iterator_adaptor& operator-(Distance x) const;
    -};
    -
    -template <class B, class P, class V, class R, class Ptr, 
    -    class C, class D1, class D2>
    -iterator_adaptor<B,P,V,R,Ptr,C,D1>
    -operator+(iterator_adaptor<B,P,V,R,Ptr,C,D1>, D2);
    -
    -template <class B, class P, class V, class R, class Ptr,
    -    class C, class D1, class D2>
    -iterator_adaptor<B,P,V,R,P,C,D1>
    -operator+(D2, iterator_adaptor<B,P,V,R,Ptr,C,D1> p);
    -
    -template <class B1, class B2, class P, class V1, class V2,
    -    class R1, class R2, class P1, class P2, class C, class D>
    -Distance operator-(const iterator_adaptor<B1,P,V1,R1,P1,C,D>&, 
    -                   const iterator_adaptor<B2,P,V2,R2,P2,C,D>&);
    -
    -template <class B1, class B2, class P, class V1, class V2,
    -    class R1, class R2, class P1, class P2, class C, class D>
    -bool operator==(const iterator_adaptor<B1,P,V1,R1,P1,C,D>&, 
    -                const iterator_adaptor<B2,P,V2,R2,P2,C,D>&);
    -
    -// and similarly for operators !=, <, <=, >=, >
     
    -

    Example

    +

    Template Parameters

    -

    It is often useful to automatically apply some function to the - value returned by dereferencing (operator*()) an - iterator. The transform - iterator makes it easy to create an iterator adaptor that does - just that. Here we will show how easy it is to implement the - transform iterator using the iterator_adaptor class.

    +

    Although iterator_adaptor takes seven template parameters, + defaults have been carefully chosen to minimize the number of parameters you + must supply in most cases, especially if BaseType is an iterator. + + + + + + + + + + +
    Parameter + + Description + +
    BaseType + + The type being wrapped. + +
    Policies + + A policy class + that supplies core functionality to the resulting iterator. A + detailed description can be found below. + +
    Value + + The value_type of the resulting iterator, unless const. If Value is + const X, a conforming compiler makes the + value_type non-const X[1].
    + Default: + std::iterator_traits<BaseType>::value_type + +
    Pointer + + The pointer type of the resulting iterator, and in + particular, the result type of operator->().
    + Default: If Value was supplied, then Value*, + otherwise std::iterator_traits<BaseType>::pointer. + +
    Reference + + The reference type of the resulting iterator, and in + particular, the result type of operator*().
    + Default: If Value is supplied, Value& is + used. Otherwise + std::iterator_traits<BaseType>::reference is used. + +
    Category + + The iterator_category type for the resulting iterator.
    + Default: + std::iterator_traits<BaseType>::iterator_category + +
    Distance + + The difference_type for the resulting iterator.
    + Default: + std::iterator_traits<BaseType>::difference_type +
    + +

    The Policies Class

    The main task in using iterator_adaptor is creating an - appropriate Policies class (a general description of the - policy class technique can be found here). + appropriate Policies class. - The Policies class that you pass in will become the heart of - the iterator adaptor, supplying the core iterator operations that will - determine how your new adaptor class will behave. The core iterator - operations are: + The Policies class will become the functional heart of the iterator + adaptor, supplying the core iterator operations that will determine how your + new adaptor class will behave. The iterator_adaptor template + defines all of the operators required of a + + Random Access Iterator. + Your Policies class must implement three, four, or seven of the core + iterator operations below depending on the iterator categories you want it to support. -