在线文档教程
C++
容器 | Containers

std::forward_list

STD:向前[医]列单

Defined in header
template< class T, class Allocator = std::allocator<T> > class forward_list;(1)(since C++11)
namespace pmr { template <class T> using forward_list = std::forward_list<T, std::pmr::polymorphic_allocator<T>>; }(2)(since C++17)

std::forward_list是一个容器,它支持从容器中的任何地方快速插入和移除元素。不支持快速随机访问。它是作为一个单链接列表实现的,与C中的实现相比,它基本上没有任何开销。std::list当不需要双向迭代时,这个容器提供了更多的空间高效存储。

添加、删除和移动列表中的元素,或跨多个列表,并不会使当前引用列表中其他元素的迭代器失效。但是,当删除相应的元素时,引用元素的迭代器或引用将失效。erase_after从名单中占29%。

std::forward_list满足…的要求Container%28,除size成员函数operator==%27s的复杂度总是线性的%29,AllocatorAwareContainerSequenceContainer...

模板参数

T-The type of the elements. The requirements that are imposed on the elements depend on the actual operations performed on the container. Generally, it is required that element type is a complete type and meets the requirements of Erasable, but many member functions impose stricter requirements. (until C++17) The requirements that are imposed on the elements depend on the actual operations performed on the container. Generally, it is required that element type meets the requirements of Erasable, but many member functions impose stricter requirements. This container (but not its members) can be instantiated with an incomplete element type if the allocator satisfies the allocator completeness requirements. (since C++17)The requirements that are imposed on the elements depend on the actual operations performed on the container. Generally, it is required that element type is a complete type and meets the requirements of Erasable, but many member functions impose stricter requirements.(until C++17)The requirements that are imposed on the elements depend on the actual operations performed on the container. Generally, it is required that element type meets the requirements of Erasable, but many member functions impose stricter requirements. This container (but not its members) can be instantiated with an incomplete element type if the allocator satisfies the allocator completeness requirements.(since C++17)
The requirements that are imposed on the elements depend on the actual operations performed on the container. Generally, it is required that element type is a complete type and meets the requirements of Erasable, but many member functions impose stricter requirements.(until C++17)
The requirements that are imposed on the elements depend on the actual operations performed on the container. Generally, it is required that element type meets the requirements of Erasable, but many member functions impose stricter requirements. This container (but not its members) can be instantiated with an incomplete element type if the allocator satisfies the allocator completeness requirements.(since C++17)
Allocator-An allocator that is used to acquire/release memory and to construct/destroy the elements in that memory. The type must meet the requirements of Allocator. The behavior is undefined if Allocator::value_type is not the same as T.

成员类型

Member typeDefinition
value_typeT
allocator_typeAllocator
size_typeUnsigned integer type (usually std::size_t)
difference_typeSigned integer type (usually std::ptrdiff_t)
referencevalue_type&
const_referenceconst value_type&
pointerstd::allocator_traits<Allocator>::pointer
const_pointerstd::allocator_traits<Allocator>::const_pointer
iteratorForwardIterator
const_iteratorConstant forward iterator

成员函数

(constructor)constructs the forward_list (public member function)
(destructor)destructs the forward_list (public member function)
operator=assigns values to the container (public member function)
assignassigns values to the container (public member function)
get_allocatorreturns the associated allocator (public member function)

元素存取

前端访问第一个元素%28公共成员函数%29

迭代器

以前[医]开始前[医]在开始%28公共成员函数%29之前,BEGIN返回一个迭代器到元素

BEGINCBEGIN将迭代器返回到开头%28的公共成员函数%29

End cend将迭代器返回到End%28公共成员函数%29

容量

空检查容器是否为空%28公共成员函数%29

马克斯[医]Size返回元素的最大可能数%28公共成员函数%29

修饰符

清除内容%28公共成员功能%29

插入[医]插入元素后,元素%28公共成员函数%29

座落[医]在元素%28公共成员函数%29之后构造元素

擦除[医]在元素%28公共成员函数%29之后删除元素后

推[医]前端插入元素到开头%28公共成员函数%29

座落[医]前端在开始处构造一个元素,它位于%28公共成员函数%29的开头。

波普[医]前端移除第一个元素%28公共成员函数%29

调整大小更改存储的元素数%28公共成员函数%29

交换交换内容%28公共成员函数%29

操作

合并两个排序列表%28公共成员函数%29

接合[医]在将元素从另一个向前移动之后[医]列表%28公共成员功能%29

移除[医]如果删除满足特定条件的元素%28公共成员函数%29

反转元素%28公共成员函数%29的顺序

唯一删除连续重复元素%28公共成员函数%29

排序元素%28公共成员函数%29

非会员职能

operator==operator!=operatoroperator>=lexicographically compares the values in the forward_list (function template)
std::swap(std::forward_list) (C++11)specializes the std::swap algorithm (function template)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/container/Forward[医]列单