Question about stl code

I read some codes implementing iterate in STL and I'm puzzled by it's definition :(partly)

template <class T,class Ref,class Ptr>
struct __iterator
{
typedef __iterator<T,T&,T*> iterator;
typedef T value_type;
typedef Ref reference;
typedef Ptr pointer;
typedef __iterator self;
...


I think it should be:
template <class T>
struct __iterator
{
typedef __iterator<T,T&,T*> iterator;
typedef T value_type;
typedef T& reference;
typedef T* pointer;
typedef __iterator self;
...


I would be very grateful if someone can tell me the reason.
What implementation are you looking at, specifically?

In any case, the iterators for the standard containers obtain their pointer and reference typedefs from the allocator used by the container and they are not necessarily the same as T* and T&: custom allocators can use all sort of non-trivial addressing mechanisms. For example, boost.interprocess uses offset_ptr<T> instead.
The implementation is sgi-stl ( g++. 2.91.57)
I read the code later and now I can understand why.
This __iterator struct would be used in the implementations of containers like below:
typedef __iterator<T,T&,T*> iterator;
typedef __iterator<T,const T&,const T*> const_iterator;
I think that's one reason to use "typename Ref/Ptr". ,not just T.
Certainly this is not the only reason ,and you are right ,if the allocator of a container does not use the trivial pointer and reference of Class-T but a special struct or something to manipulate the element memory in the container,Ptr is more suitable than T*.
I didn't read the code of boost and I want to read it later to confirm it.
Thank you for your guidance.
Topic archived. No new replies allowed.