c++templatestypestype-definition

Question regarding to the type in C++ template of _deque_iterator


I am studying the code of Deque Itereator.

template <class T, class Ref, class Ptr, size_t BufSiz>
class _deque_iterator
{
    typedef _deque_iterator<T, T&, T*, BufSiz> iterator; 
    typedef _deque_iterator<T, const T&, const T*, BufSiz> const_iterator; 
    static size_t buffer_size() { return _deque_buf_size(BufSiz, sizeof(T)); }

    typedef random_access_iterator_tag iterator_category; 
    typedef T value_type; 
    typedef Ptr pointer; 
    typedef Ref reference;
    typedef size_t size_type; 
    typedef ptrdiff_t difference_type; 
    typedef T** map_pointer; 

    typedef _deque_iterator self; 

    T* cur; 
    T* first; 
    T* last; 

    map_pointer node;
....
}

I am wondering if it make any difference if I replace T* with Ptr, as in:

Ptr cur; 
Ptr first; 
Ptr last; 

Similarly another question, the member map is used to store an arrary of Ptr pointing to the buffer area, can I also change the type like:

//typedef T** map_pointer;
typedef Ptr* map_pointer;

Would it lead to any inconvenience when using this template? or these 2 ways are just equal? Thanks for your comments.


Solution

  • Would it lead to any inconvenience when using this template?

    It would (probably) cease to work for const_iterator, because you have changed from T * data members to const T *. Especially map_pointer, where there isn't an implicit conversion from T ** to const T **.