Vector of STL source code

Source: Internet
Author: User

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:

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.