C++ Reference: Standard C++ Library reference: Containers: deque: deque

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

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

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

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

成员类型
C++98

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 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<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 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_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)

iterator: 
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)

allocator: 
get_allocator    Get allocator (public member function) 

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weixin_40186813

你的能量无可限量。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值