From cppreference.com
This header is part of the
library.
Includes
(C++20)
support
(C++11)
class template
Classes
(C++11)
singly-linked list
(class template)
Functions
operator==operator!=operator<operator<=operator>operator>=operator<=>
(C++11)(C++11)(removed in C++20)(C++11)(removed in C++20)(C++11)(removed in C++20)(C++11)(removed in C++20)(C++11)(removed in C++20)(C++20)
lexicographically compares the values of two forward_lists
(function template)
(C++11)
specializes the
algorithm
(function template)
erase(std::forward_list)erase_if(std::forward_list)
(C++20)
erases all elements satisfying specific criteria
(function template)
Range access
(C++11)(C++14)
returns an iterator to the beginning of a container or array
(function template)
(C++11)(C++14)
returns an iterator to the end of a container or array
(function template)
(C++14)
returns a reverse iterator to the beginning of a container or array
(function template)
(C++14)
returns a reverse end iterator for a container or array
(function template)
(C++17)(C++20)
returns the size of a container or array
(function template)
(C++17)
checks whether the container is empty
(function template)
(C++17)
obtains the pointer to the underlying array
(function template)
Synopsis
#include<compare>#include<initializer_list>namespacestd{// class template forward_listtemplate<classT,classAllocator=allocator<T>>classforward_list;template<classT,classAllocator>constexprbooloperator==(constforward_list<T,Allocator>&x,constforward_list<T,Allocator>&y);template<classT,classAllocator>constexpr/*synth-three-way-result*/<T>operator<=>(constforward_list<T,Allocator>&x,constforward_list<T,Allocator>&y);template<classT,classAllocator>constexprvoidswap(forward_list<T,Allocator>&x,forward_list<T,Allocator>&y)noexcept(noexcept(x.swap(y)));// erasuretemplate<classT,classAllocator,classU=T>constexprtypenameforward_list<T,Allocator>::size_typeerase(forward_list<T,Allocator>&c,constU&value);template<classT,classAllocator,classPredicate>constexprtypenameforward_list<T,Allocator>::size_typeerase_if(forward_list<T,Allocator>&c,Predicatepred);namespacepmr{template<classT>usingforward_list=std::forward_list<T,polymorphic_allocator<T>>;}}Class template
namespacestd{template<classT,classAllocator=allocator<T>>classforward_list{public:// typesusingvalue_type=T;usingallocator_type=Allocator;usingpointer=allocator_traits<Allocator>::pointer;usingconst_pointer=allocator_traits<Allocator>::const_pointer;usingreference=value_type&;usingconst_reference=constvalue_type&;usingsize_type=/* implementation-defined */;usingdifference_type=/* implementation-defined */;usingiterator=/* implementation-defined */;usingconst_iterator=/* implementation-defined */;// construct/copy/destroyconstexprforward_list():forward_list(Allocator()){}constexprexplicitforward_list(constAllocator&);constexprexplicitforward_list(size_typen,constAllocator&=Allocator());constexprforward_list(size_typen,constT&value,constAllocator&=Allocator());template<classInputIter>constexprforward_list(InputIterfirst,InputIterlast,constAllocator&=Allocator());template<container-compatible-range<T>R>constexprforward_list(from_range_t,R&&rg,constAllocator&=Allocator());constexprforward_list(constforward_list&x);constexprforward_list(forward_list&&x);constexprforward_list(constforward_list&x,consttype_identity_t<Allocator>&);constexprforward_list(forward_list&&x,consttype_identity_t<Allocator>&);constexprforward_list(initializer_list<T>,constAllocator&=Allocator());constexpr~forward_list();constexprforward_list&operator=(constforward_list&x);constexprforward_list&operator=(forward_list&&x)noexcept(allocator_traits<Allocator>::is_always_equal::value);constexprforward_list&operator=(initializer_list<T>);template<classInputIter>constexprvoidassign(InputIterfirst,InputIterlast);template<container-compatible-range<T>R>constexprvoidassign_range(R&&rg);constexprvoidassign(size_typen,constT&t);constexprvoidassign(initializer_list<T>);constexprallocator_typeget_allocator()constnoexcept;// iteratorsconstexpriteratorbefore_begin()noexcept;constexprconst_iteratorbefore_begin()constnoexcept;constexpriteratorbegin()noexcept;constexprconst_iteratorbegin()constnoexcept;constexpriteratorend()noexcept;constexprconst_iteratorend()constnoexcept;constexprconst_iteratorcbegin()constnoexcept;constexprconst_iteratorcbefore_begin()constnoexcept;constexprconst_iteratorcend()constnoexcept;// capacityconstexprboolempty()constnoexcept;constexprsize_typemax_size()constnoexcept;// element accessconstexprreferencefront();constexprconst_referencefront()const;// modifierstemplate<class...Args>constexprreferenceemplace_front(Args&&...args);constexprvoidpush_front(constT&x);constexprvoidpush_front(T&&x);template<container-compatible-range<T>R>constexprvoidprepend_range(R&&rg);constexprvoidpop_front();template<class...Args>constexpriteratoremplace_after(const_iteratorposition,Args&&...args);constexpriteratorinsert_after(const_iteratorposition,constT&x);constexpriteratorinsert_after(const_iteratorposition,T&&x);constexpriteratorinsert_after(const_iteratorposition,size_typen,constT&x);template<classInputIter>constexpriteratorinsert_after(const_iteratorposition,InputIterfirst,InputIterlast);constexpriteratorinsert_after(const_iteratorposition,initializer_list<T>il);template<container-compatible-range<T>R>constexpriteratorinsert_range_after(const_iteratorposition,R&&rg);constexpriteratorerase_after(const_iteratorposition);constexpriteratorerase_after(const_iteratorposition,const_iteratorlast);constexprvoidswap(forward_list&)noexcept(allocator_traits<Allocator>::is_always_equal::value);constexprvoidresize(size_typesz);constexprvoidresize(size_typesz,constvalue_type&c);constexprvoidclear()noexcept;// forward_list operationsconstexprvoidsplice_after(const_iteratorposition,forward_list&x);constexprvoidsplice_after(const_iteratorposition,forward_list&&x);constexprvoidsplice_after(const_iteratorposition,forward_list&x,const_iteratori);constexprvoidsplice_after(const_iteratorposition,forward_list&&x,const_iteratori);constexprvoidsplice_after(const_iteratorposition,forward_list&x,const_iteratorfirst,const_iteratorlast);constexprvoidsplice_after(const_iteratorposition,forward_list&&x,const_iteratorfirst,const_iteratorlast);constexprsize_typeremove(constT&value);template<classPredicate>constexprsize_typeremove_if(Predicatepred);constexprsize_typeunique();template<classBinaryPredicate>constexprsize_typeunique(BinaryPredicatebinary_pred);constexprvoidmerge(forward_list&x);constexprvoidmerge(forward_list&&x);template<classCompare>constexprvoidmerge(forward_list&x,Comparecomp);template<classCompare>constexprvoidmerge(forward_list&&x,Comparecomp);constexprvoidsort();template<classCompare>constexprvoidsort(Comparecomp);constexprvoidreverse()noexcept;};template<classInputIter,classAllocator=allocator</*iter-value-type*/<InputIter>>>forward_list(InputIter,InputIter,Allocator=Allocator())->forward_list</*iter-value-type*/<InputIter>,Allocator>;template<ranges::input_rangeR,classAllocator=allocator<ranges::range_value_t<R>>>forward_list(from_range_t,R&&,Allocator=Allocator())->forward_list<ranges::range_value_t<R>,Allocator>;}