Vector of STL source code
1. SGI Vector
Sgi stl vector inherits a child base class:
Template <typename _ TP, typename _ alloc = STD: Allocator <_ TP>
Class vector: protected _ vector_base <_ TP, _ alloc>
Some basic operations are defined in the base class, and the basic three pointers required by the vector are encapsulated:
Struct _ vector_impl
: Public _ tp_alloc_type
{
Pointer _ m_start;
Pointer _ m_finish;
Pointer _ m_end_of_storage;
...
}
Public:
_ Vector_impl _ m_impl;
Use _ m_impl as a data member.
Now we only express the same meaning in one class.
2. Basic Meaning of Vector
Template <typename _ TP, typename _ alloc = STD: Allocator <_ TP> class vector: protected _ vector_base <_ TP, _ alloc> {// required nested type, must contain five types in iterator_traits
Public: typedef _ TP value_type; typedef typename _ base: pointer; typedef typename _ alloc_traits: const_pointer identifier; typedef typename _ alloc_traits: Reference reference; typedef typename _ alloc_traits :: const_reference; typedef _ gnu_cxx ::__ normal_iterator <pointer, vector> iterator; typedef _ gnu_cxx ::__ operator <const_pointer, vector> identifier; typedef STD :: struct <const_iterator> struct; typedef STD: reverse_iterator <iterator> struct; typedef size_t size_type; typedef ptrdiff_t difference_type; typedef _ alloc allocator_type;
Protect: