STL deque的介绍(1)

原文地址:http://www.cplusplus.com/reference/deque/deque/
class template
<deque>

std::deque

template < class T, class Alloc = allocator<T> > class deque;
Double ended queue

deque (usually pronounced like "deck") is an irregular acronym of double-ended queue. Double-ended queues are sequence containers with dynamic sizes that can be expanded or contracted on both ends (either its front or its back).

双端队列(很像“列车”)是一种不规则的有两个结尾的队列缩写。两边结尾的队列容器可以从两边动态增长或者缩小。(从它的头部或者尾部)。


Specific libraries may implement deques in different ways, generally as some form of dynamic array. But in any case, they allow for the individual elements to be accessed directly through random access iterators, with storage handled automatically by expanding and contracting the container as needed.

不同的库可能用不同的方法实现deques,一般都是由动态数组构成,但在任何情况下,他们允许使用随即访问迭代器直接访问其中的任何元素,使用内存操纵其动态增长以及缩小。


Therefore, they provide a functionality similar to vectors, but with efficient insertion and deletion of elements also at the beginning of the sequence, and not only at its end. But, unlike vectorsdeques are not guaranteed to store all its elements in contiguous storage locations: accessing elements in a deque by offsetting a pointer to another element causes undefined behavior.

因此,他们提供类似vector的功能,但是提供了更高效的在序列头部插入以及删除元素的方法,在其尾部也是一样,但是不同与vector,deques不保证将所有的元素连续地存放那个在内存的位置,使用deque的指针偏移访问另一个元素将会导致为定义的行为。


Both vectors and deques provide a very similar interface and can be used for similar purposes, but internally both work in quite different ways: While vectors use a single array that needs to be occasionally reallocated for growth, the elements of a deque can be scattered in different chunks of storage, with the container keeping the necessary information internally to provide direct access to any of its elements in constant time and with a uniform sequential interface (through iterators). Therefore, deques are a little more complex internally than vectors, but this allows them to grow more efficiently under  certain circumstances, especially with very long sequences, where reallocations become more expensive.

vector和deque都提供了相似的接口用于相似的功能。但是在内部是以不同的方式实现的。当vector像普通数组一样使用时需要偶尔重分配以实现增长,deque却可以在不同的块上分散存放元素,容器依旧保持必须的信息以提供在常量时间内对其元素的直接访问,因此,deques内部比vector要复杂一些,但是他依旧允许在确定的环境下高效增长,特别是在长的序列中,重分配操作会变得消耗很昂贵!


For operations that involve frequent insertion or removals of elements at positions other than the beginning or the end, deques perform worse and have less consistent iterators and references than lists and forward lists.

如果需要在begin和end之外的位置频繁地插入或者移除元素,deque的表现比list以及forward list要差很多。


Container properties

Sequence
Elements in sequence containers are ordered in a strict linear sequence. Individual elements are accessed by their position in this sequence.
Dynamic array
Generally implemented as a dynamic array, it allows direct access to any element in the sequence and provides relatively fast addition/removal of elements at the beginning or the end of the sequence.
Allocator-aware
The container uses an allocator object to dynamically handle its storage needs.

Template parameters

T
Type of the elements.
Aliased as member type deque::value_type.
Alloc
Type of the allocator object used to define the storage allocation model. By default, the allocator class template is used, which defines the simplest memory allocation model and is value-independent.
Aliased as member type deque::allocator_type.

Member types

member typedefinitionnotes
value_typeThe first template parameter (T)
allocator_typeThe second template parameter (Alloc)defaults to: allocator<value_type>
referenceallocator_type::referencefor the default allocatorvalue_type&
const_referenceallocator_type::const_referencefor the default allocatorconst value_type&
pointerallocator_type::pointerfor the default allocatorvalue_type*
const_pointerallocator_type::const_pointerfor the default allocatorconst value_type*
iteratorrandom access iterator to value_typeconvertible to const_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 ofdifference_typeusually the same as size_t

Member functions


Iterators:

Capacity:

Element access:

Modifiers:


Allocator:

Non-member functions overloads




——————————————————————————————————————————————————————————————————

//翻译的不好的地方请多多指导,可以在下面留言或者点击左上方邮件地址给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。

转载请注明出处:http://blog.csdn.net/qq844352155
author:天下无双

Email:coderguang@gmail.com

2014-9-1

于GDUT

——————————————————————————————————————————————————————————————————














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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值