[4]探讨list

容器list。

template <class T>
struct __list_node
{
    typedef void* void_pointer;
    void_pointer prev;
    void_pointer next;
    T data;
};

template <class T,class Alloc = alloc>
class list
{
protected:
    typedef __listnode<T> list_node;

public:
    typedef list_node* link_type;
    typedef __list_iterator<T, T&, T*> iterator;
protected:
    link_type node;
};

template<class T,class ref,class Ptr>
struct __list_iterator
{
    typedef T value_type;
    typedef Ptr pointer;
    typedef Ref refenrece;
... };

在对于lterator里面,i++和++i,通过一个参数来区分开

我们可以去查看源码:

    _List_iterator& operator++() {
        _Mybase::operator++();
        return *this;
    }
//前++

    _List_iterator operator++(int) {
        _List_iterator _Tmp = *this;
        _Mybase::operator++();
        return _Tmp;
    }
//后++

-----//复杂,待补充-----

原文地址:https://www.cnblogs.com/EvansPudding/p/12567633.html