Cpp Standard Library 简明教程
C++ Library - <deque>
Introduction
Deque 是 *D*ouble *E*nded *Que*ue 的缩写。它是一个可以改变其大小运行时的序列容器。容器是一个包含同类型数据的对象。序列容器按线性顺序严格存储元素。
Deque is acronym for *D*ouble *E*nded *Que*ue. It is a sequence container that can change it’s size runtime. Container is an object that holds data of same type. Sequence containers store elements strictly in linear sequence.
deque 的元素可以分散在内存的不同块中。容器存储必要的信息以允许在恒定时间直接访问任何元素。与向量不同,deque 并不保证在其连续的内存位置存储所有元素。因此,它不允许通过偏移指针直接访问数据。但它允许使用下标运算符 [ ] 直接访问任何元素。
Elements of deque can be scattered in different chunks of memory. Container stores necessary information to allow direct access to any element in constant time. Unlike vectors, deque are not guaranteed to store all it’s element at contiguous memory locations. Hence it does not allow direct access to data by offsetting pointers. But it enables direct access to any element using subscript operator [ ].
deque 可以根据需要在运行时从两端收缩或扩展。存储需求由内部分配器自动满足。deque 提供与向量类似的功能,但提供了从任何一端插入和删除数据的有效方法。
Deque can shrink or expand as needed from both ends at run time. The storage requirement is fulfilled automatically by internal allocator. Deque provides similar functionality as vectors, but provides efficient way to insert and delete data from any end.
大小为零的双端队列也是有效的。在这种情况下,deque.begin() 和 deque.end() 指向相同的位置。但调用 front() 或 back() 的行为是未定义的。
Zero sized deques are also valid. In that case deque.begin() and deque.end() points to same location. But behavior of calling front() or back() is undefined.
Definition
以下是 <deque> 头文件中的 std::deque 的定义
Below is definition of std::deque from <deque> header file
template < class T, class Alloc = allocator<T> > class deque;
Parameters
-
T − Type of the element contained. T may be substituted by any other data type including user-defined type.
-
Alloc − Type of allocator object. By default, the allocator class template is used, which defines the simplest memory allocation model and is value-independent.