C++ std::list
std::list
template < class T, class Alloc = allocator > class list;
List
Lists are sequence containers that allow constant time insert and erase operations anywhere within the sequence, and iteration in both directions.
List containers are implemented as doubly-linked lists; Doubly linked lists can store each of the elements they contain in different and unrelated storage locations. The ordering is kept internally by the association to each element of a link to the element preceding it and a link to the element following it.
They are very similar to forward_list: The main difference being that forward_list objects are single-linked lists, and thus they can only be iterated forwards, in exchange for being somewhat smaller and more efficient.
Compared to other base standard sequence containers (array, vector and deque), lists perform generally better in inserting, extracting(提取) and moving elements in any position within the container for which an iterator has already been obtained, and therefore also in algorithms that make intensive use of these, like sorting algorithms.
The main drawback(缺点) of lists and forward_lists compared to these other sequence containers is that they lack direct access to the elements by their position; For example, to access the sixth element in a list, one has to iterate from a known position (like the beginning or the end) to that position, which takes linear time in the distance between these. They also consume some extra memory to keep the linking information associated to each element (which may be an important factor for large lists of small-sized elements).
Container properties
- Sequence: Elements in sequence containers are ordered in a strict linear sequence. Individual elements are accessed by their position in this sequence.
- Doubly-linked list: Each element keeps information on how to locate the next and the previous elements, allowing constant time insert and erase operations before or after a specific element (even of entire ranges), but no direct random access.
- Allocator-aware: The container uses an allocator object to dynamically handle its storage needs.
Template parameters
- T: Type of the elements. Aliased as member type list::value_type.
- Alloc: Type of the allocator object used to define the storage allocation model. By default, the allocator class template is used, which defines the simplest memory allocation model and is value-independent. Aliased as member type list::allocator_type.
Member types
| member type | definition | notes |
|---|---|---|
| value_type | The first template parameter (T) | |
| allocator_type | The second template parameter (Alloc) | defaults to: allocator |
| reference | allocator_type::reference | for the default allocator: value_type& |
| const_reference | allocator_type::const_reference | for the default allocator: const value_type& |
| pointer | allocator_type::pointer | for the default allocator: value_type* |
| const_pointer | allocator_type::const_pointer | for the default allocator: const value_type* |
| iterator | a bidirectional iterator to value_type | convertible to const_iterator |
| const_iterator | a bidirectional iterator to const value_type | |
| reverse_iterator | reverse_iterator | |
| const_reverse_iterator | reverse_iterator | |
| difference_type | a signed integral type, identical to: iterator_traits::difference_type | usually the same as ptrdiff_t |
| size_type | an unsigned integral type that can represent any non-negative value of difference_type | usually the same as size_t |
Member functions
- (constructor): Construct list (public member function )
- (destructor): List destructor (public member function )
- operator=: Assign content (public member function )
Iterators:
- 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 )
Capacity:
- empty: Test whether container is empty (public member function )
- size: Return size (public member function )
- max_size: Return maximum size (public member function )
Element access:
- front: Access first element (public member function )
- back: Access last element (public member function )
Modifiers:
- 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 )
Operations:
- 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 )
Observers:
- get_allocator: Get allocator (public member function )
Non-member function overloads
- relational operators (list): Relational operators for list (function )
- swap (list): Exchanges the contents of two lists (function template )
Code Exaple
Reference
C++ std::list的更多相关文章
- 【NX二次开发】NX内部函数,libuifw.dll文件中的内部函数
本文分为两部分:"带参数的函数"和 "带修饰的函数". 浏览这篇博客前请先阅读: [NX二次开发]NX内部函数,查找内部函数的方法 带参数的函数: void U ...
- C++ std::set
std::set template < class T, // set::key_type/value_type class Compare = less<T>, // set::k ...
- C++ std::priority_queue
std::priority_queue template <class T, class Container = vector<T>, class Compare = less< ...
- C++ std::queue
std::queue template <class T, class Container = deque<T> > class queue; FIFO queue queue ...
- C++ std::multimap
std::multimap template < class Key, // multimap::key_type class T, // multimap::mapped_type class ...
- C++ std::map
std::map template < class Key, // map::key_type class T, // map::mapped_type class Compare = less ...
- C++ std::forward_list
std::forward_list template < class T, class Alloc = allocator > class forward_list; Forward li ...
- C++ std::deque
std::deque template < class T, class Alloc = allocator > class deque; Double ended queue deque ...
- C++ std::array
std::array template < class T, size_t N > class array; Code Example #include <iostream> ...
随机推荐
- PHP源码分析-变量
1. 变量的三要素变量名称,变量类型,变量值 那么在PHP用户态下变量类型都有哪些,如下: // Zend/zend.h #define IS_NULL 0 #define IS_LONG 1 #de ...
- 【Win 10 应用开发】在App所在的进程中执行后台任务
在以往版本中,后台任务都是以独立的专用进程来运行,因此,定义后台任务代码的类型都要位于 Windows 运行时组件项目中. 不过,在14393中,SDK 作了相应的扩展,不仅支持以前的独立进程中运行后 ...
- 关于 devbridge-autocomplete 插件多选操作的实现方法
目前据我所知最好用的 autocomplete 插件就是 jquery-ui 的 autocomplete 以及 devbridge 的 autocomplete 插件. 我最终选择了 devbrid ...
- python 3.5 成功安装 scrapy 的步骤
http://www.cnblogs.com/hhh5460/p/5814275.html
- IteratorPattern(迭代子模式)
/** * 迭代子模式 * @author TMAC-J * 聚合:某一类对象的集合 * 迭代:行为方式,用来处理聚合 * 是一种行为模式,用于将聚合本身和操作聚合的行为分离 * Java中的COLL ...
- AlloyTouch实战--60行代码搞定QQ看点资料卡
原文链接:https://github.com/AlloyTeam/AlloyTouch/wiki/kandian 先验货 访问DEMO你也可以点击这里 源代码可以点击这里 如你体验所见,流程的滚动的 ...
- 一个软件开发者的BPM之路
我是小林,一名普通的软件工程师,从事BPM(业务流程管理)软件开发工作.我没有几十年的技术底蕴,无法像大牛们一样高谈阔论,品评BPM开发之道:也不是资深的流程管理专家,能与大家分析流程管理的时弊.我只 ...
- 【SAP业务模式】之ICS(一):业务详述
PS:本专题系列讲述如何在SAP系统中实现ICS的业务模式,本系列博文系原创,如要转载引用,请保持原文一致并注明出处! SAP系统自身功能非常强大,支持多种业务模式,通过前台后台的配置就可以实现多种效 ...
- Lucene4.4.0 开发之排序
排序是对于全文检索来言是一个必不可少的功能,在实际运用中,排序功能能在某些时候给我们带来很大的方便,比如在淘宝,京东等一些电商网站我们可能通过排序来快速找到价格最便宜的商品,或者通过排序来找到评论数最 ...
- 如何使用dos命令查看MySQL当前使用的数据库?
1.dos命令安装mysqld --stall.启动net start mysql.进入MySQL数据库mysql -uroot -p后,输入select database(); 如图: