C++ vector解析 (C++ 11)


本文在我另外一个博客也同步:http://www.cnblogs.com/pengjunwei/p/4414677.html
Vector表示可以改变大小的数组容器。
 
就像数组,其元素的向量使用连续的存储位置,这意味着还可以访问其元素上使用偏移量经常指向元素的指针,和在数组中一样有效。但与数组不同,其大小可动态变化,他们的存储容器自动处理。
在vector内部,使用动态分配的数组向量来存储他们的内容。此数组可能需要重新分配,以便规模的扩大新元素被插入时,这意味着为它分配一个新的数组,并将所有元素。这是一种相对较昂贵的任务在处理时间方面,因此,向量不重新分配每个时间元素添加到容器。
Vector,Deque,List 三个容器同属序列容器,操作统一。


类型如下:
member typedefinitionnotes
value_typeThe first template parameter (T) 
allocator_typeThe second template parameter (Alloc)defaults to:allocator<value_type>
referencevalue_type& 
const_referenceconst value_type& 
pointerallocator_traits<allocator_type>::pointerfor the default allocator:value_type*
const_pointerallocator_traits<allocator_type>::const_pointerfor the default allocator:const value_type*
iteratorrandom access iterator to value_typeconvertible toconst_iterator
const_iteratorrandom access iterator to const value_type 
reverse_iteratorreverse_iterator<iterator> 
const_reverse_iteratorreverse_iterator<const_iterator> 
difference_typea signed integral type, identical to: iterator_traits<iterator>::difference_typeusually the same as ptrdiff_t
size_typean unsigned integral type that can represent any non-negative value of difference_typeusually the same as size_t
 
 
Vector操作接口如下:
(部分来自其他实现)

上诉接口的实现:


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值