您的位置:首页 > 产品设计 > UI/UE

STL deque的介绍(1)

2014-09-01 10:00 218 查看
原文地址: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

SequenceElements in sequence containers are ordered in a strict linear sequence. Individual elements are accessed by their position in this sequence.Dynamic arrayGenerally 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-awareThe container uses an allocator object to dynamically handle its storage needs.


Template parameters

TType of the elements.

Aliased as member type deque::value_type.
AllocType 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

C++98

C++11



member typedefinitionnotes
value_typeThe first template parameter (T)
allocator_typeThe second template parameter (Alloc)defaults to: allocator<value_type>
referenceallocator_type::referencefor the default allocator: value_type&
const_referenceallocator_type::const_referencefor the default allocator: const value_type&
pointerallocator_type::pointerfor the default allocator: value_type*
const_pointerallocator_type::const_pointerfor the default allocator: const 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

(constructor)
Construct deque container (public member function )(destructor)
Deque destructor (public member function )operator=
Assign content (public member function )
Iterators:

begin
Return iterator to beginning (public member function )end
Return iterator to end (public member function )rbegin
Return reverse iterator to reverse beginning (public member function )rend
Return reverse iterator to reverse end (public member function )cbegin 
Return const_iterator to beginning (public member function )cend 
Return const_iterator to end (public member function )crbegin 
Return const_reverse_iterator to reverse beginning (public member function )crend 
Return const_reverse_iterator to reverse end (public member function )
Capacity:

size
Return size (public member function )max_size
Return maximum size (public member function )resize
Change size (public member function )empty
Test whether container is empty (public member function )shrink_to_fit 
Shrink to fit (public member function )
Element access:

operator[]
Access element (public member function )at
Access element (public member function )front
Access first element (public member function )back
Access last element (public member function )
Modifiers:

assign
Assign container content (public member function )push_back
Add element at the end (public member function )push_front
Insert element at beginning (public member function )pop_back
Delete last element (public member function )pop_front
Delete first element (public member function )insert
Insert elements (public member function )erase
Erase elements (public member function )swap
Swap content (public member function )clear
Clear content (public member function )emplace 
Construct and insert element (public member function )emplace_front 
Construct and insert element at beginning (public member function )emplace_back 
Construct and insert element at the end (public member function )
Allocator:

get_allocator
Get allocator (public member function )


Non-member functions overloads

relational operators
Relational operators for deque (function )swap

Exchanges the contents of two deque containers (function template )

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

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

转载请注明出处:http://blog.csdn.net/qq844352155

author:天下无双

Email:coderguang@gmail.com

2014-9-1

于GDUT

——————————————————————————————————————————————————————————————————
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  STL STL deque deque