C++ Reference: Standard C++ Library reference: Containers: deque: deque
admin
2024-03-23 19:44:39
0次

C++官网参考链接:https://cplusplus.com/reference/deque/deque/

类模板

std::deque
template < class T, class Alloc = allocator > class deque;
双端队列
deque(通常发音像"deck")是双端队列的不规则首字母缩写。双端队列是具有动态大小的顺序容器,可以在两端(前端或后端)进行扩展或收缩。
特定的库可能以不同的方式实现双端队列,通常是作为动态数组的某种形式。但在任何情况下,它们都允许通过随机访问迭代器直接访问单个元素,并根据需要通过扩展和收缩容器自动处理存储。
因此,它们提供了类似于vectors的功能,但可以在序列的开头高效地插入和删除元素,而不仅仅是在序列的末尾。但是,与vectors不同,deques不能保证将其所有元素存储在连续的存储位置:通过偏移指向另一个元素的指针来访问双端队列中的元素会导致未定义的行为。
vectors和双端队列都提供了非常相似的接口,也可以用于类似的目的,但在内部它们的工作方式却截然不同:vector使用一个单独的数组,需要偶尔重新分配以实现增长,而双端队列的元素可以分散在不同的存储块中,容器在内部保存必要的信息,以便在恒定的时间内通过统一的顺序接口(通过迭代器)直接访问其任何元素。因此,双端队列在内部比vectors更复杂一些,但这允许它们在某些情况下更有效地增长,特别是对于非常长的序列,在这种情况下重新分配会变得更加昂贵。
对于包含频繁插入或删除除开始或结束位置以外的元素的操作,双端队列的性能较差,迭代器和引用的一致性不如lists和forward lists。

容器的属性
按顺序排列
顺序容器中的元素按照严格的线性顺序排列。各个元素通过它们在该序列中的位置进行访问。
动态数组
它通常作为动态数组实现,允许直接访问序列中的任何元素,并在序列的开头或结尾提供相对快速的添加/删除元素。
能够感知的内存分配器
容器使用分配器对象动态处理其存储需求。

模板形参 
T
元素的类型。
别名为成员类型deque::value_type。
Alloc
用于定义存储分配模型的分配器对象的类型。默认情况下,使用分配器(allocator)类模板,它定义了最简单的内存分配模型,并且与值无关。
别名为成员类型deque::allocator_type。

成员类型
C++98

member typedefinitionnotes
value_typeThe first template parameter (T)
allocator_typeThe second template parameter (Alloc)defaults to: allocator
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*
iteratora random access iterator to value_typeconvertible to const_iterator
const_iteratora random access iterator to const value_type
reverse_iteratorreverse_iterator
const_reverse_iteratorreverse_iterator
difference_typea signed integral type, identical to: iterator_traits::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

C++11

member typedefinitionnotes
value_typeThe first template parameter (T)
allocator_typeThe second template parameter (Alloc)defaults to: allocator
referencevalue_type&
const_referenceconst value_type&
pointerallocator_traits::pointerfor the default allocator: value_type*
const_pointerallocator_traits::const_pointerfor the default allocator: const value_type*
iteratora random access iterator to value_typeconvertible to const_iterator
const_iteratora random access iterator to const value_type
reverse_iteratorreverse_iterator
const_reverse_iteratorreverse_iterator
difference_typea signed integral type, identical to:
iterator_traits::difference_type
usually 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

成员函数
(constructor)    Construct deque container (public member function)
(destructor)    Deque destructor (public member function)
operator=    Assign content (public member function)

迭代器: 
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)

容量:
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)

元素访问:
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)

修改器:
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)

分配器: 
get_allocator    Get allocator (public member function) 

非成员函数重载: 
relational operators    Relational operators for deque (function)
swap    Exchanges the contents of two deque containers (function template)

相关内容

热门资讯

AI做攻略、“双向奔赴”……国... 本文转自:人民网人民网记者 许维娜今年国庆假期,AI(人工智能)成了不少年轻人的“旅行搭子”。行前做...
合肥的这个“梗”, 翻篇了 社交平台的评论区,曾长期流传一句专属于合肥的黑色幽默。有人问合肥哪里好玩,本地网友半开玩笑地回复:合...
7万+旅游中高层都在的群,今天... 做旅游这行,资源卡位、渠道互通、项目落地——往往就差一个“对的机会”。我们的行业社群已聚集70,00...
一场帐篷音乐节,如何让井研从“... 帐篷音乐节现场封面新闻记者 周洪攀10月的研溪湿地,晚风里裹着柑橘的清甜与民谣的回响。夜幕降临,10...
白鹤翩翩落星愿,上海迪士尼度假... 10月9日,世界候鸟日前夕,上海迪士尼度假区星愿公园的湖风里多了一分白鹤的灵动。三座白鹤雕塑正式揭幕...
成都锦江边赏初秋枫叶飘飘 目前,成都锦江边国华街枫叶树红了。近年来,国华街附近的几条街都栽种了红枫树,是城区较集中看枫叶的点位...
GBTA:商务旅行正在复苏,但... 亚太正在成为全球商务旅行增长的重要引擎。在经历疫情后的快速反弹之后,全球商务旅行正在进入一个新的增长...
从景区焕新到节赛引流 邹城双节... 齐鲁网·闪电新闻10月9日讯 中秋、国庆“双节”假期,邹城市文化和旅游局提前谋划、周密部署,立足自身...
江山如此多娇 且看石楼今朝 金秋十月,黄河岸畔秋意盎然,丰收盛会喜迎国庆。本次石楼国庆文旅活动以“江山如此多娇,且看石楼今朝”为...
海南国庆假期接待游客475.4... 2026年国庆假期,海南接待游客475.40万人次,较2025年增长13.1%,较2024年增长15...