Struct DequeIterator

Synopsis

#include <include/EASTL/deque.h>

template <typename T, typename Pointer, typename Reference, unsigned kDequeSubarraySize>
struct DequeIterator

Description

DequeIterator

The DequeIterator provides both const and non-const iterators for deque. It also is used for the tracking of the begin and end for the deque.

Structures

Decrement
FromConst
Increment

Methods

DequeIterator overloadDequeIterator.
copy overload
copy_backward overload
operator*
operator+
operator++ overload
operator+=
operator-
operator-- overload
operator-=
operator->
SetSubarray

Source

Lines 151-247 in include/EASTL/deque.h.

template <typename T, typename Pointer, typename Reference, unsigned kDequeSubarraySize>
struct DequeIterator
{
    typedef DequeIterator<T, Pointer, Reference, kDequeSubarraySize>  this_type;
    typedef DequeIterator<T, T*, T&, kDequeSubarraySize>              iterator;
    typedef DequeIterator<T, const T*, const T&, kDequeSubarraySize>  const_iterator;
    typedef ptrdiff_t                                                 difference_type;
    typedef EASTL_ITC_NS::random_access_iterator_tag                  iterator_category;
    typedef T                                                         value_type;
    typedef T*                                                        pointer;
    typedef T&                                                        reference;
public:
    DequeIterator();
    DequeIterator(const iterator& x);
    pointer   operator->() const;
    reference operator*() const;
    this_type& operator++();
    this_type  operator++(int);
    this_type& operator--();
    this_type  operator--(int);
    this_type& operator+=(difference_type n);
    this_type& operator-=(difference_type n);
    this_type operator+(difference_type n) const;
    this_type operator-(difference_type n) const;
protected:
    template <typename, typename, typename, unsigned>
    friend struct DequeIterator;
    template <typename, typename, unsigned>
    friend struct DequeBase;
    template <typename, typename, unsigned>
    friend class deque;
    template <typename U, typename PointerA, typename ReferenceA, typename PointerB, typename ReferenceB, unsigned kDequeSubarraySizeU>
    friend bool operator==(const DequeIterator<U, PointerA, ReferenceA, kDequeSubarraySizeU>&, 
                           const DequeIterator<U, PointerB, ReferenceB, kDequeSubarraySizeU>&);
    template <typename U, typename PointerA, typename ReferenceA, typename PointerB, typename ReferenceB, unsigned kDequeSubarraySizeU>
    friend bool operator!=(const DequeIterator<U, PointerA, ReferenceA, kDequeSubarraySizeU>&, 
                           const DequeIterator<U, PointerB, ReferenceB, kDequeSubarraySizeU>&);
    template <typename U, typename PointerU, typename ReferenceU, unsigned kDequeSubarraySizeU>
    friend bool operator!=(const DequeIterator<U, PointerU, ReferenceU, kDequeSubarraySizeU>& a, 
                           const DequeIterator<U, PointerU, ReferenceU, kDequeSubarraySizeU>& b);
    template <typename U, typename PointerA, typename ReferenceA, typename PointerB, typename ReferenceB, unsigned kDequeSubarraySizeU>
    friend bool operator< (const DequeIterator<U, PointerA, ReferenceA, kDequeSubarraySizeU>&, 
                           const DequeIterator<U, PointerB, ReferenceB, kDequeSubarraySizeU>&);
    template <typename U, typename PointerA, typename ReferenceA, typename PointerB, typename ReferenceB, unsigned kDequeSubarraySizeU>
    friend bool operator> (const DequeIterator<U, PointerA, ReferenceA, kDequeSubarraySizeU>&, 
                           const DequeIterator<U, PointerB, ReferenceB, kDequeSubarraySizeU>&);
    template <typename U, typename PointerA, typename ReferenceA, typename PointerB, typename ReferenceB, unsigned kDequeSubarraySizeU>
    friend bool operator<=(const DequeIterator<U, PointerA, ReferenceA, kDequeSubarraySizeU>&, 
                           const DequeIterator<U, PointerB, ReferenceB, kDequeSubarraySizeU>&);
    template <typename U, typename PointerA, typename ReferenceA, typename PointerB, typename ReferenceB, unsigned kDequeSubarraySizeU>
    friend bool operator>=(const DequeIterator<U, PointerA, ReferenceA, kDequeSubarraySizeU>&, 
                           const DequeIterator<U, PointerB, ReferenceB, kDequeSubarraySizeU>&);
    template <typename U, typename PointerA, typename ReferenceA, typename PointerB, typename ReferenceB, unsigned kDequeSubarraySizeU>
    friend typename DequeIterator<U, PointerA, ReferenceA, kDequeSubarraySizeU>::difference_type
    operator-(const DequeIterator<U, PointerA, ReferenceA, kDequeSubarraySizeU>& a,
              const DequeIterator<U, PointerB, ReferenceB, kDequeSubarraySizeU>& b);
protected:
    T*  mpCurrent;          // Where we currently point. Declared first because it's used most often.
    T*  mpBegin;            // The beginning of the current subarray.
    T*  mpEnd;              // The end of the current subarray. To consider: remove this member, as it is always equal to 'mpBegin + kDequeSubarraySize'. Given that deque subarrays usually consist of hundreds of bytes, this isn't a massive win. Also, now that we are implementing a zero-allocation new deque policy, mpEnd may in fact not be equal to 'mpBegin + kDequeSubarraySize'.
    T** mpCurrentArrayPtr;  // Pointer to current subarray. We could alternatively implement this as a list node iterator if the deque used a linked list.
    struct Increment {};
    struct Decrement {};
    struct FromConst {};
    DequeIterator(T** pCurrentArrayPtr, T* pCurrent);
    DequeIterator(const const_iterator& x, FromConst) : mpCurrent(x.mpCurrent), mpBegin(x.mpBegin), mpEnd(x.mpEnd), mpCurrentArrayPtr(x.mpCurrentArrayPtr){}
    DequeIterator(const iterator&       x, Increment);
    DequeIterator(const iterator&       x, Decrement);
    this_type copy(const iterator& first, const iterator& last, true_type);  // true means that value_type has the type_trait has_trivial_relocate,
    this_type copy(const iterator& first, const iterator& last, false_type); // false means it does not. 
    void copy_backward(const iterator& first, const iterator& last, true_type);  // true means that value_type has the type_trait has_trivial_relocate,
    void copy_backward(const iterator& first, const iterator& last, false_type); // false means it does not.
    void SetSubarray(T** pCurrentArrayPtr);
};





Add Discussion as Guest

Log in