C++ Reference: Standard C++ Library reference: Containers: list: list
创始人
2024-03-06 02:16:48
0

C++参考链接:https://cplusplus.com/reference/list/list/

类模板 

std::list
template < class T, class Alloc = allocator > class list;
列表 
列表是顺序容器,允许在序列中的任何位置进行固定时间的插入和删除操作,并允许双向迭代。
列表容器被实现为双链表;双链表可以将它们包含的每个元素存储在不同的、不相关的存储位置。顺序在内部通过与前面元素的链接和后面元素的链接的每个元素的关联来保持。
它们与forward_list非常相似:主要的区别是forward_list对象是单链表,因此它们只能向前迭代,以换取更小和更高效。
与其他基本标准顺序容器(array、vector和deque)相比,list在插入、提取元素和移动元素到容器内已经获得迭代器的任何位置方面通常表现得更好,因此在大量使用这些元素的算法(如排序算法)中也表现得更好。
与其他序列容器相比,lists和forward_list的主要缺点是它们不能通过位置直接访问元素;例如,要访问列表中的第6个元素,必须从已知位置(如开始或结束)迭代到该位置,这需要以这些位置之间的距离为线性的时间。它们还消耗一些额外的内存来保持与每个元素相关联的链接信息(这可能是包含小型元素的大型列表的一个重要因素)。

容器的属性
按顺序排列的 
顺序容器中的元素按照严格的线性顺序排列。各个元素通过它们在该序列中的位置进行访问。
双向链接列表
每个元素都保存关于如何定位下一个和上一个元素的信息,允许在特定元素之前或之后(甚至是整个范围)进行固定时间的插入和删除操作,但不能直接随机访问。
能够感知的分配器 
容器使用分配器对象动态处理其存储需求。

模板形参 
T
元素的类型。
别名为成员类型list::value_type。
Alloc
用于定义存储分配模型的分配器对象的类型。默认情况下,使用allocator类模板,它定义了最简单的内存分配模型,并且与值无关。
别名为成员类型list::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 bidirectional iterator to value_typeconvertible to const_iterator
const_iteratora bidirectional 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 bidirectional iterator to value_typeconvertible to const_iterator
const_iteratora bidirectional 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 list (public member function)
(destructor)   List 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)

容量: 
empty    Test whether container is empty (public member function)
size    Return size (public member function)
max_size    Return maximum size (public member function)

元素访问: 
front    Access first element (public member function)
back    Access last element (public member function)

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

操作: 
splice    Transfer elements from list to list (public member function)
remove    Remove elements with specific value (public member function)
remove_if    Remove elements fulfilling condition (public member function template)
unique    Remove duplicate values (public member function)
merge    Merge sorted lists (public member function)
sort    Sort elements in container (public member function)
reverse    Reverse the order of elements (public member function)

观测器: 
get_allocator    Get allocator (public member function)

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

相关内容

热门资讯

海南自贸区涨停潮背后:政策红利... 12月22日上午,A股市场迎来久违的“多点开花”——三大指数齐涨,而最引人注目的,莫过于海南自贸区板...
深圳:深入实施跨境贸易投资高水... 人民财讯12月23日电,深圳市人民政府印发《深圳市进一步加大吸引和利用外资实施办法》,其中提出,进一...
国家发展改革委等三部门完善幼儿... 中新网12月23日电 据国家发展改革委网站消息,近日,为深入贯彻党的二十大和二十届历次全会精神,落实...
建工修复(300958)披露累... 截至2025年12月23日收盘,建工修复(300958)报收于12.39元,较前一交易日下跌0.88...
红豆股份(600400)披露拟... 截至2025年12月23日收盘,红豆股份(600400)报收于2.4元,较前一交易日下跌2.83%,...
凌钢股份与江苏银行深圳分行纠纷... 12月23日,凌钢股份(600231)发布公告,近期公司收到辽宁省朝阳市中级人民法院的民事裁定书,案...
科蓝软件:科蓝盛合陷合同纠纷 ... 12月23日,科蓝软件(300663)发布公告,控股股东一致行动人宁波科蓝盛合投资管理合伙企业(有限...
广东潮州通报“因购物纠纷引发的... 本文转自【看潮州客户端】; 情况简讯 记者获悉,12月18日,在市区枫春路发生一起因购物纠纷引发的殴...