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


Containers
标准容器
容器是一个持有者对象,它存储了其他对象(其元素)的集合。它们被实现为类模板,这使得作为元素支持的类型具有很大的灵活性。
容器管理其元素的存储空间,并提供访问它们的成员函数,可以直接或通过iterator(具有与指针类似属性的reference对象)。
容器复制编程中非常常用的结构:动态数组(vector)、队列(queue)、堆栈(stack)、堆(priority_queue)、链表(list)、树(set)、关联数组(map)……

许多容器有几个共同的成员函数,并共享功能。决定使用哪种类型的容器来满足特定的需求通常不仅仅取决于容器所提供的功能,还取决于它的一些成员的效率(复杂度)。对于顺序容器来说尤其如此,它们在插入/删除元素和访问元素之间提供了不同的复杂度权衡。
stackqueuepriority_queue被实现为 容器适配器。容器适配器不是完整的容器类,而是提供特定接口的类,这些接口依赖于一个容器类(如dequelist)的对象来处理元素。底层容器被封装成这样一种方式: 容器适配器的成员可以独立于所使用的底层 容器类访问其元素。

容器类模板
顺序容器:
array Array class (class template)
vector Vector (class template)
deque Double ended queue (class template)
forward_list Forward list (class template)
list List (class template)

容器适配器:
stack LIFO stack (class template)
queue FIFO queue (class template)
priority_queue Priority queue (class template)

关联容器:
set Set (class template)
multiset Multiple-key set (class template)
map Map (class template)
multimap Multiple-key map (class template)

成员图谱
这是一个比较图表,每个不同的容器上都有不同的成员函数:

C++98Available since C++98C++11New in C++11

顺序容器

Headers

Members

operator=

iteratorsbegin

end

rbegin

rend

const iteratorscbegin

cend

crbegin

crend

capacitysize

max_size

empty

resize

shrink_to_fit

capacity

reserve

element accessfront

back

operator[]

modifiersassign

emplace

insert

erase

emplace_back

push_back

pop_back

emplace_front

push_front

pop_front

clear

swap

list operationssplice

remove

remove_if

unique

merge

sort

reverse

observersget_allocator

data

关联容器

Headers

Members

iteratorsbegin

end

rbegin

rend

const iteratorscbegin

cend

crbegin

crend

capacitysize

max_size

empty

reserve

element accessat

operator[]

modifiersemplace

emplace_hint

insert

erase

clear

swap

operationscount

find

equal_range

lower_bound

upper_bound

observersget_allocator

key_comp

value_comp

key_eq

hash_function

bucketsbucket

bucket_count

bucket_size

max_bucket_count

hash policyrehash

load_factor

max_load_factor

Original: https://blog.csdn.net/weixin_40186813/article/details/127520894
Author: weixin_40186813
Title: C++ Reference: Standard C++ Library reference: Containers

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/661355/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球