I am studying the source codes of SGI STL and have many problems with it.
I can't figure out the design choice of the iterator of SGI STL as follow
template <class _Tp, class _Ref, class _Ptr>
struct _Slist_iterator : public _Slist_iterator_base
{
typedef _Slist_iterator<_Tp, _Tp&, _Tp*> iterator; #1
typedef _Slist_iterator<_Tp, const _Tp&, const _Tp*> const_iterator; #2
typedef _Slist_iterator<_Tp, _Ref, _Ptr> _Self; #3
};
Why don't just change the _Slist_iterator to the way as #4 and #5
template <class _Tp>
struct _Slist_iterator : public _Slist_iterator_base
{
typedef _Slist_iterator<_Tp> iterator; #4
typedef _Slist_iterator<_Tp> const iterator const_iterator; #5
};
I mimic the slist of SGI STL and rewrite an simple version(for practice)
and change #1,#2,#3 to #4 and #5.The codes work, I don't what is the
reason to define the const_iterator and self like #2 and #3.
the source codes are a little bit long, I upload them to the link
https://sites.google.com/site/noviceatc/important-documents/sgi_stl_practice_slist_00.rar?attredirects=0&d=1
The part of algorithms(except of sort) are pretty easy to cope up with,
but the containers part are pretty difficult for me.
Iterator is an important glue for STL, but I don't understand the design
choice of the iterator of SGI STL, could you tell me why ?Thanks.