STD::FORWARD_LIST(3)
π¦ std::forward_list< _Tp, _Alloc > β Library Functions Manual π¦
π NAME π
Bestie, meet std::forward_list< _Tp, _Alloc > β a standard container with linear time access to elements, and fixed time insertion/deletion at any point in the sequence.
β¨ SYNOPSIS β¨
#include <forward_list>
Inherits std::_Fwd_list_base< _Tp, _Alloc >.
π Public Types π
The whole cast of typedefs, no cap:
typedef _Alloc allocator_typetypedef _Base::const_iterator const_iteratortypedef _Alloc_traits::const_pointer const_pointertypedef const value_type & const_referencetypedef std::ptrdiff_t difference_typetypedef _Base::iterator iteratortypedef _Alloc_traits::pointer pointertypedef value_type & referencetypedef std::size_t size_typetypedef _Tp value_type
π Public Member Functions π
All the member function lore, in order, periodt:
forward_list ()=defaultβ Makes an empty forward_list, zero elements, clean slate energy.template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>> forward_list (_InputIterator __first, _InputIterator __last, const _Alloc &__al=_Alloc())β Builds a forward_list from a range, bestie.forward_list (const _Alloc &__al) noexceptβ Creates a forward_list with no elements, allocator edition.forward_list (const forward_list &__list)β The forward_list copy constructor, doing copy things.forward_list (const forward_list &__list, const __type_identity_t< _Alloc > &__al)β Copy constructor but with an allocator argument, slay.forward_list (forward_list &&)=defaultβ The forward_list move constructor, moving on up.forward_list (forward_list &&__list, const __type_identity_t< _Alloc > &__al) noexcept(_Node_alloc_traits::_S_always_equal())β Move constructor with allocator argument, periodt.forward_list (size_type __n, const _Alloc &__al=_Alloc())β Creates a forward_list with default constructed elements, iykyk.forward_list (size_type __n, const _Tp &__value, const _Alloc &__al=_Alloc())β Creates a forward_list with copies of an exemplar element, copy copy.forward_list (std::initializer_list< _Tp > __il, const _Alloc &__al=_Alloc())β Builds a forward_list from an initializer_list, curly brace realness.~forward_list () noexceptβ The forward_list dtor, sheβs leaving.template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>> void assign (_InputIterator __first, _InputIterator __last)β Assigns a range to a forward_list, range assignment.void assign (size_type __n, const _Tp &__val)β Assigns a given value to a forward_list, value drop.void assign (std::initializer_list< _Tp > __il)β Assigns an initializer_list to a forward_list, list style.const_iterator before_begin () const noexceptiterator before_begin () noexceptconst_iterator begin () const noexceptiterator begin () noexceptconst_iterator cbefore_begin () const noexceptconst_iterator cbegin () const noexceptconst_iterator cend () const noexceptvoid clear () noexceptβ Erases all the elements, clean sweep.template<typename... _Args> iterator emplace_after (const_iterator __pos, _Args &&... __args)β Constructs object in forward_list after the specified iterator, emplace after.template<typename... _Args> reference emplace_front (_Args &&... __args)β Constructs object in forward_list at the front of the list, front and center.bool empty () const noexceptconst_iterator end () const noexceptiterator end () noexceptiterator erase_after (const_iterator __pos)β Removes the element pointed to by the iterator following pos, bye girl.iterator erase_after (const_iterator __pos, const_iterator __last)β Remove a range of elements, range removal.reference front ()const_reference front () constallocator_type get_allocator () const noexceptβ Get a copy of the memory allocation object, allocator tea.template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>> iterator insert_after (const_iterator __pos, _InputIterator __first, _InputIterator __last)β Inserts a range into the forward_list, range insert.iterator insert_after (const_iterator __pos, _Tp &&__val)iterator insert_after (const_iterator __pos, const _Tp &__val)β Inserts given value into forward_list after specified iterator, value insert.iterator insert_after (const_iterator __pos, size_type __n, const _Tp &__val)β Inserts a number of copies of given data into the forward_list, copies on copies.iterator insert_after (const_iterator __pos, std::initializer_list< _Tp > __il)β Inserts the contents of an initializer_list into forward_list after the specified iterator, initializer_list insert.size_type max_size () const noexceptvoid merge (forward_list &&__list)β Merge sorted lists, merge moment.template<typename _Comp> void merge (forward_list &&__list, _Comp __comp)β Merge sorted lists according to comparison function, comp style.void merge (forward_list &__list)template<typename _Comp> void merge (forward_list &__list, _Comp __comp)forward_list & operator= (const forward_list &__list)β The forward_list assignment operator, assignment core.forward_list & operator= (forward_list &&__list) noexcept(_Node_alloc_traits::_S_nothrow_move())β The forward_list move assignment operator, move assignment.forward_list & operator= (std::initializer_list< _Tp > __il)β The forward_list initializer list assignment operator, init-list assignment.void pop_front ()β Removes first element, pop front.void push_front (_Tp &&__val)void push_front (const _Tp &__val)β Add data to the front of the forward_list, push front.__remove_return_type remove (const _Tp &__val)β Remove all elements equal to value, remove spree.template<typename _Pred> __remove_return_type remove_if (_Pred __pred)β Remove all elements satisfying a predicate, pred says bye.void resize (size_type __sz)β Resizes the forward_list to the specified number of elements, resize era.void resize (size_type __sz, const value_type &__val)β Resizes the forward_list to the specified number of elements, value resize.void reverse () noexceptβ Reverse the elements in list, reverse it.void sort ()β Sort the elements of the list, sort it out.template<typename _Comp> void sort (_Comp __comp)β Sort the forward_list using a comparison function, comp sort.void splice_after (const_iterator __pos, forward_list &&__list) noexceptβ Insert contents of another forward_list, splice in.void splice_after (const_iterator __pos, forward_list &&__list, const_iterator __i) noexceptβ Insert element from another forward_list, single splice.void splice_after (const_iterator __pos, forward_list &__list) noexceptvoid splice_after (const_iterator __pos, forward_list &__list, const_iterator __i) noexceptvoid swap (forward_list &__list) noexceptβ Swaps data with another forward_list, swap tea.__remove_return_type unique ()β Remove consecutive duplicate elements, unique queen.template<typename _BinPred> __remove_return_type unique (_BinPred __binary_pred)β Remove consecutive elements satisfying a predicate, pred unique.void splice_after (const_iterator __pos, forward_list &&, const_iterator __before, const_iterator __last) noexceptβ Insert range from another forward_list, range splice.void splice_after (const_iterator __pos, forward_list &, const_iterator __before, const_iterator __last) noexceptβ Insert range from another forward_list, range splice.
π Detailed Description π
Okay so hereβs the deep lore, bestie:
template<typename _Tp, typename _Alloc = allocator<_Tp>>
class std::forward_list< _Tp, _Alloc >"A standard container with linear
time access to elements, and fixed time insertion/deletion at any point
in the sequence.
β³ Since β³
C++11
π Template Parameters π
_Tpβ Type of element._Allocβ Allocator type, defaults toallocator<_Tp>.
Meets the requirements of a container, a sequence, including the optional sequence requirements with the exception of at and operator[].
This is a singly linked list. Traversal up the list requires linear time, but adding and removing elements (or nodes) is done in constant time, regardless of where the change takes place. Unlike std::vector and std::deque, random-access iterators are not provided, so subscripting ([]) access is not allowed. For algorithms which only need sequential access, this lack makes no difference.
Also unlike the other standard containers, std::forward_list provides specialized algorithms unique to linked lists, such as splicing, sorting, and in-place reversal.
π Constructor & Destructor Documentation π
the default constructor β forward_list () β¨
template<typename _Tp, typename _Alloc = allocator<_Tp>> std::forward_list< _Tp, _Alloc >::forward_list () [default]
Okay so this one literally just makes a forward_list with no elements. Empty. A vibe. Nothing in it. π«
Referenced byinsert_after(),insert_after(),merge(),operator=(),remove(),remove_if(),resize(),resize(),sort(),splice_after(), andunique().
forward_list (const _Alloc & __al) π
template<typename _Tp, typename _Alloc = allocator<_Tp>> std::forward_list< _Tp, _Alloc >::forward_list (const _Alloc & __al) [inline], [explicit], [noexcept]
Makes a forward_list with no elements β but bestie, you get to hand it the allocator yourself. Very demure, very mindful. π
Parameters
__alβ an allocator object.
forward_list (const forward_list< _Tp, _Alloc > & __list, const __type_identity_t< _Alloc > & __al) π¦
template<typename _Tp, typename _Alloc = allocator<_Tp>> std::forward_list< _Tp, _Alloc >::forward_list (const forward_list< _Tp, _Alloc > & __list, const __type_identity_t< _Alloc > & __al) [inline]
The copy constructor with an allocator argument, i.e. copy this list but use my allocator, thanks. β¨
Parameters
__listβ input list to copy.__alβ an allocator object.
forward_list (forward_list< _Tp, _Alloc > && __list, const __type_identity_t< _Alloc > & __al) π₯
template<typename _Tp, typename _Alloc = allocator<_Tp>> std::forward_list< _Tp, _Alloc >::forward_list (forward_list< _Tp, _Alloc > && __list, const __type_identity_t< _Alloc > & __al) [inline], [noexcept]
The move constructor with an allocator argument. Same energy, but the list gets moved instead of copied. No cap. π¨
Parameters
__listβ input list to move.__alβ an allocator object.
forward_list (size_type __n, const _Alloc & __al = _Alloc()) πΈ
template<typename _Tp, typename _Alloc = allocator<_Tp>> std::forward_list< _Tp, _Alloc >::forward_list (size_type __n, const _Alloc & __al = _Alloc()) [inline], [explicit]
Creates a forward_list with default constructed elements β you say how many, it gives you that many lil default-constructed babies. π£
Parameters
__nβ the number of elements to initially create.__alβ an allocator object.
This constructor creates the forward_list with __n default constructed elements.
forward_list (size_type __n, const _Tp & __value, const _Alloc & __al = _Alloc()) π
template<typename _Tp, typename _Alloc = allocator<_Tp>> std::forward_list< _Tp, _Alloc >::forward_list (size_type __n, const _Tp & __value, const _Alloc & __al = _Alloc()) [inline]
Creates a forward_list with copies of an exemplar element β one iconic element, duplicated __n times. It's giving clone army. π
Parameters
__nβ the number of elements to initially create.__valueβ an element to copy.__alβ an allocator object.
This constructor fills the forward_list with __n copies of __value.
forward_list (_InputIterator __first, _InputIterator __last, const _Alloc & __al = _Alloc()) π
template<typename _Tp, typename _Alloc = allocator<_Tp>> template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>> std::forward_list< _Tp, _Alloc >::forward_list (_InputIterator __first, _InputIterator __last, const _Alloc & __al = _Alloc()) [inline]
Builds a forward_list from a range. Bestie, this is the iterator-to-iterator glow-up. π¦
Parameters
__firstβ an input iterator.__lastβ an input iterator.__alβ an allocator object.
Create a forward_list consisting of copies of the elements from [__first,__last). This is linear in N (where N is distance(__first,__last)).
forward_list (const forward_list< _Tp, _Alloc > & __list) π«Ά
template<typename _Tp, typename _Alloc = allocator<_Tp>> std::forward_list< _Tp, _Alloc >::forward_list (const forward_list< _Tp, _Alloc > & __list) [inline]
The forward_list copy constructor. Twin behavior, but make it a separate human. π
Parameters
__listβ aforward_listof identical element and allocator types.
forward_list (forward_list< _Tp, _Alloc > && ) π
template<typename _Tp, typename _Alloc = allocator<_Tp>> std::forward_list< _Tp, _Alloc >::forward_list (forward_list< _Tp, _Alloc > && ) [default]
The forward_list move constructor. Snatch the contents, leave the original standing there like πΆ.
Parameters
__listβ aforward_listof identical element and allocator types.
The newly-created forward_list contains the exact contents of the moved instance. The contents of the moved instance are a valid, but unspecified forward_list. So don't go reading it and expecting the old vibe back, okay? π
forward_list (std::initializer_list< _Tp > __il, const _Alloc & __al = _Alloc()) β¨
template<typename _Tp, typename _Alloc = allocator<_Tp>> std::forward_list< _Tp, _Alloc >::forward_list (std::initializer_list< _Tp > __il, const _Alloc & __al = _Alloc()) [inline]
Builds a forward_list from an initializer_list β the curly-brace girlies finally get their moment. π
Parameters
__ilβ aninitializer_listofvalue_type.__alβ an allocator object.
Create a forward_list consisting of copies of the elements in the initializer_list __il. This is linear in __il.size().
~forward_list () π₯
template<typename _Tp, typename _Alloc = allocator<_Tp>> std::forward_list< _Tp, _Alloc >::~forward_list () [inline], [noexcept]
The forward_list dtor. It's over, it's done, it's goodbye. βοΈ No exceptions though β [noexcept], so no dramatic exits.
β¨ Member Function Documentation β¨
assign (_InputIterator __first, _InputIterator __last) π«
template<typename _Tp, typename _Alloc = allocator<_Tp>> template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>> void std::forward_list< _Tp, _Alloc >::assign (_InputIterator __first, _InputIterator __last) [inline]
Assigns a range to a forward_list. Whole new personality, sourced from an iterator pair. π
Parameters
__firstβ an input iterator.__lastβ an input iterator.
This function fills a forward_list with copies of the elements in the range [ __first,__last).
Note that the assignment completely changes the forward_list and that the number of elements of the resulting forward_list is the same as the number of elements assigned. Like, full rebrand, no leftovers. π
Referenced bystd::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(),operator=(),std::forward_list< _Tp, polymorphic_allocator< _Tp > >::operator=(), andstd::forward_list< _Tp, polymorphic_allocator< _Tp > >::operator=().
assign (size_type __n, const _Tp & __val) π₯
template<typename _Tp, typename _Alloc = allocator<_Tp>> void std::forward_list< _Tp, _Alloc >::assign (size_type __n, const _Tp & __val) [inline]
Assigns a given value to a forward_list. One value, repeated __n times, main character energy only. π
Parameters
__nβ number of elements to be assigned.__valβ value to be assigned.
This function fills a forward_list with __n copies of the given value. Note that the assignment completely changes the forward_list, and that the resulting forward_list has __n elements.
assign (std::initializer_list< _Tp > __il) π
template<typename _Tp, typename _Alloc = allocator<_Tp>> void std::forward_list< _Tp, _Alloc >::assign (std::initializer_list< _Tp > __il) [inline]
Assigns an initializer_list to a forward_list. Brace yourself. Literally. π
Parameters
__ilβ aninitializer_listofvalue_type.
Replace the contents of the forward_list with copies of the elements in the initializer_list __il. This is linear in __il.size().
before_begin () const π
template<typename _Tp, typename _Alloc = allocator<_Tp>> const_iterator std::forward_list< _Tp, _Alloc >::before_begin () const [inline], [noexcept]
Returns a read-only (constant) iterator that points before the first element in the forward_list. Iteration is done in ordinary element order. Yes bestie, before the first element β it's a whole position, it's real, don't fight it. π
before_begin () π«§
template<typename _Tp, typename _Alloc = allocator<_Tp>> iterator std::forward_list< _Tp, _Alloc >::before_begin () [inline], [noexcept]
Returns a read/write iterator that points before the first element in the forward_list. Iteration is done in ordinary element order. Same spot, but now you have βοΈ permissions.
Referenced bystd::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(),std::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(),insert_after(),insert_after(),resize(), andresize().
begin () const β
template<typename _Tp, typename _Alloc = allocator<_Tp>> const_iterator std::forward_list< _Tp, _Alloc >::begin () const [inline], [noexcept]
Returns a read-only (constant) iterator that points to the first element in the forward_list. Iteration is done in ordinary element order. Look, don't touch. π
begin () π
template<typename _Tp, typename _Alloc = allocator<_Tp>> iterator std::forward_list< _Tp, _Alloc >::begin () [inline], [noexcept]
Returns a read/write iterator that points to the first element in the forward_list. Iteration is done in ordinary element order. Now you can touch. Slay. π
Referenced bystd::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(),std::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(), andunique().
cbefore_begin () const π¦
template<typename _Tp, typename _Alloc = allocator<_Tp>> const_iterator std::forward_list< _Tp, _Alloc >::cbefore_begin () const [inline], [noexcept]
Returns a read-only (constant) iterator that points before the first element in the forward_list. Iteration is done in ordinary element order. The c is for const, not for cute, but honestly? Both. π
Referenced bystd::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(),std::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(),std::forward_list< _Tp, polymorphic_allocator< _Tp > >::emplace_front(),std::forward_list< _Tp, polymorphic_allocator< _Tp > >::push_front(),remove(),remove_if(), andunique().
cbegin () const π
template<typename _Tp, typename _Alloc = allocator<_Tp>> const_iterator std::forward_list< _Tp, _Alloc >::cbegin () const [inline], [noexcept]
Returns a read-only (constant) iterator that points to the first element in the forward_list. Iteration is done in ordinary element order.
Referenced by std::operator==().
cend () const π
template<typename _Tp, typename _Alloc = allocator<_Tp>> const_iterator std::forward_list< _Tp, _Alloc >::cend () const [inline], [noexcept]
Returns a read-only (constant) iterator that points one past the last element in the forward_list. Iteration is done in ordinary element order. One past the last one β it's the void, it's the beyond, it's giving liminal space. π«₯
Referenced by std::operator==().
clear () π§Ή
template<typename _Tp, typename _Alloc = allocator<_Tp>> void std::forward_list< _Tp, _Alloc >::clear () [inline], [noexcept]
Erases all the elements. Big reset. Fresh start. β¨
Important bestie: note that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility. So likeβ¦ if you leaked, that's on you, not on clear(). π
Referenced bystd::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(),std::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(),operator=(), andstd::forward_list< _Tp, polymorphic_allocator< _Tp > >::operator=().
emplace_after (const_iterator __pos, _Args &&... __args) πΈ
template<typename _Tp, typename _Alloc = allocator<_Tp>> template<typename... _Args> iterator std::forward_list< _Tp, _Alloc >::emplace_after (const_iterator __pos, _Args &&... __args) [inline]
Constructs an object in the forward_list after the specified iterator. Right behind __pos, sneaking in. π
Parameters
__posβ aconst_iteratorinto theforward_list.__argsβ arguments.
Returns
- An iterator that points to the inserted data. π«Ά
This function will insert an object of type T constructed with T(std::forward<Args>(args)...) after the specified location. Due to the nature of a forward_list this operation can be done in constant time, and does not invalidate iterators and references. Iconic behavior honestly. π
emplace_front (_Args &&... __args) π₯
template<typename _Tp, typename _Alloc = allocator<_Tp>> template<typename... _Args> reference std::forward_list< _Tp, _Alloc >::emplace_front (_Args &&... __args) [inline]
Constructs an object in the forward_list at the front of the list. Front row seats, no waiting. π
Parameters
__argsβ arguments.
This function will insert an object of type Tp constructed with Tp(std::forward<Args>(args)...) at the front of the list. Due to the nature of a forward_list this operation can be done in constant time, and does not invalidate iterators and references. Periodt. π
empty () const π«
template<typename _Tp, typename _Alloc = allocator<_Tp>> bool std::forward_list< _Tp, _Alloc >::empty () const [inline], [noexcept]
Returns true if the forward_list is empty. (Thus begin() would equal end().) It's the vibe check β is there anything in here or are we just standing in an empty room? π
Referenced byinsert_after(), andsort().
π¦ end() β the const edition, i.e. look but don't touch
template<typename _Tp, typename _Alloc = allocator<_Tp>> const_iterator
std::forward_list< _Tp, _Alloc >::end () const [inline], [noexcept]
Okay so this hands you a read-only iterator that points one past the last element in the forward_list. That's the classic "past-the-end" marker, bestie β you don't dereference it, you just use it to know when you've run out of list. Iteration happens in ordinary element order, no surprises, no plot twists. β¨
π
end() β the non-const edition, full send
template<typename _Tp, typename _Alloc = allocator<_Tp>> iterator
std::forward_list< _Tp, _Alloc >::end () [inline], [noexcept]
Same vibe, but this one gives you a read/write iterator pointing one past the last element. So you can actually mess with the elements you walk over. Again: ordinary element order, periodt.
π Referenced bystd::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(),std::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(),insert_after(),insert_after(),resize(),resize(), andunique().
β¨ erase_after(const_iterator __pos) β bye bye, one element
template<typename _Tp, typename _Alloc = allocator<_Tp>> iterator
std::forward_list< _Tp, _Alloc >::erase_after (const_iterator __pos)
[inline]
Removes the element that the iterator following pos is pointing at. Yes, following β it's a forward_list, we live one step ahead of ourselves here. π
Parameters
__posβ iterator pointing before the element to be erased.
Returns
- An iterator pointing to the element following the one that was erased, or
end()if no such element exists.
This function erases the element at the given position and thus shortens the forward_list by one.
Because of the whole forward-only nature of a forward_list, this operation can be done in constant time, and it only invalidates iterators/references to the element being removed. Slay.
β οΈ Heads up, bestie: the user is cautioned that this function only erases the element, and that if the element is itself a pointer, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility. No cap.
π Referenced bystd::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(),std::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(),resize(), andresize().
πΈ erase_after(const_iterator __pos, const_iterator __last) β bye bye, a whole range
template<typename _Tp, typename _Alloc = allocator<_Tp>> iterator
std::forward_list< _Tp, _Alloc >::erase_after (const_iterator __pos,
const_iterator __last) [inline]
Remove a range of elements. Group eviction, honestly. π§
Parameters
__posβ iterator pointing before the first element to be erased.__lastβ iterator pointing to one past the last element to be erased.
Returns
__last
This function erases the elements in the range (__pos,__last) and shortens the forward_list accordingly.
This operation is linear time in the size of the range, and only invalidates iterators/references to the element being removed.
β οΈ Same warning as before, and it matters: the user is cautioned that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility. π
π front() β the non-const glow-up
template<typename _Tp, typename _Alloc = allocator<_Tp>> reference
std::forward_list< _Tp, _Alloc >::front () [inline]
Returns a read/write reference to the data at the first element of the forward_list. That's your front-row seat, literally.
π Referenced by std::forward_list< _Tp, polymorphic_allocator< _Tp > >::emplace_front().
π front() β the const edition
template<typename _Tp, typename _Alloc = allocator<_Tp>> const_reference
std::forward_list< _Tp, _Alloc >::front () const [inline]
Returns a read-only (constant) reference to the data at the first element of the forward_list. Look, don't touch. π
π get_allocator() β where the memory magic is stored
template<typename _Tp, typename _Alloc = allocator<_Tp>> allocator_type
std::forward_list< _Tp, _Alloc >::get_allocator () const [inline],
[noexcept]
Get a copy of the memory allocation object. That's it, that's the whole thing. It's giving "here's the allocator, bestie, do with it what you will". β¨
π Referenced byinsert_after(),insert_after(),remove(),remove_if(), andunique().
π¦ insert_after(const_iterator __pos, _InputIterator __first, _InputIterator __last) β the range insert
template<typename _Tp, typename _Alloc> template<typename _InputIterator,
typename> forward_list< _Tp, _Alloc >::iterator
forward_list::insert_after (const_iterator __pos, _InputIterator
__first, _InputIterator __last)
Inserts a range into the forward_list.
Parameters
__posβ an iterator into theforward_list.__firstβ an input iterator.__lastβ an input iterator.
Returns
- An iterator pointing to the last inserted element, or
__posif__first == __last.
This function inserts copies of the data in the range [ __first, __last) into the forward_list after the location specified by __pos.
This operation is linear in the number of elements inserted, and it does not invalidate iterators and references. Iconic behaviour, honestly.
References forward_list(), before_begin(), empty(), end(), and get_allocator().
π insert_after(const_iterator __pos, const _Tp & __val) β the single-value insert
template<typename _Tp, typename _Alloc = allocator<_Tp>> iterator
std::forward_list< _Tp, _Alloc >::insert_after (const_iterator __pos,
const _Tp & __val) [inline]
Inserts the given value into the forward_list after the specified iterator.
Parameters
__posβ an iterator into theforward_list.__valβ data to be inserted.
Returns
- An iterator that points to the inserted data.
This function inserts a copy of the given value after the specified location. Due to the nature of a forward_list, this operation can be done in constant time, and does not invalidate iterators and references. Main character energy from a tiny operation, fr fr. π₯
π Referenced bystd::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(),std::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(),std::forward_list< _Tp, polymorphic_allocator< _Tp > >::insert_after(), andresize().
β insert_after(const_iterator __pos, size_type __n, const _Tp & __val) β the n-copies insert
template<typename _Tp, typename _Alloc> forward_list< _Tp, _Alloc
>::iterator forward_list::insert_after (const_iterator __pos, size_type
__n, const _Tp & __val)
Inserts a number of copies of the given data into the forward_list.
Parameters
__posβ an iterator into theforward_list.__nβ number of elements to be inserted.__valβ data to be inserted.
Returns
- An iterator pointing to the last inserted copy of
val, orposifn == 0.
This function inserts a specified number of copies of the given data after the location specified by pos.
This operation is linear in the number of elements inserted, and does not invalidate iterators and references.
References forward_list(), before_begin(), end(), and get_allocator().
π§ insert_after(const_iterator __pos, std::initializer_list< _Tp > __il) β the curly-brace special
template<typename _Tp, typename _Alloc = allocator<_Tp>> iterator
std::forward_list< _Tp, _Alloc >::insert_after (const_iterator __pos,
std::initializer_list< _Tp > __il) [inline]
Inserts the contents of an initializer_list into the forward_list after the specified iterator.
Parameters
__posβ an iterator into theforward_list.__ilβ aninitializer_listofvalue_type.
Returns
- An iterator pointing to the last inserted element, or
__posif__ilis empty.
This function inserts copies of the data in the initializer_list __il into the forward_list before the location specified by __pos.
This operation is linear in the number of elements inserted, and does not invalidate iterators and references.
π«Ά max_size() β the theoretical ceiling
template<typename _Tp, typename _Alloc = allocator<_Tp>> size_type
std::forward_list< _Tp, _Alloc >::max_size () const [inline],
[noexcept]
Returns the largest possible number of elements of forward_list. Dream big, bestie. β¨
π merge(forward_list< _Tp, _Alloc > && __list) β merging two sorted lists
template<typename _Tp, typename _Alloc = allocator<_Tp>> void
std::forward_list< _Tp, _Alloc >::merge (forward_list< _Tp, _Alloc > &&
__list) [inline]
Merge sorted lists. Two sorted queens, one list. π
Parameters
__listβ sorted list to merge.
Assumes that both __list and this list are sorted according to operator<(). Merges the elements of __list into this list in sorted order, leaving __list empty when complete. Elements in this list precede elements in __list that are equal.
π Referenced by std::forward_list< _Tp, polymorphic_allocator< _Tp > >::merge().
π merge(forward_list< _Tp, _Alloc > && __list, _Comp __comp) β merging with your own rules
template<typename _Tp, typename _Alloc> template<typename _Comp> void
forward_list::merge (forward_list< _Tp, _Alloc > && __list, _Comp
__comp)
Merge sorted lists according to a comparison function. You bring the vibes, it brings the order. π
Parameters
__listβ sorted list to merge.__compβ comparison function defining sort order.
Assumes that both __list and this list are sorted according to comp. Merges the elements of __list into this list in sorted order, leaving __list empty when complete. Elements in this list precede elements in __list that are equivalent according to comp().
References forward_list(), std::__addressof(), and std::move().
π operator=(const forward_list< _Tp, _Alloc > & __list) β the copy assignment
template<typename _Tp, typename _Alloc> forward_list< _Tp, _Alloc > &
forward_list::operator= (const forward_list< _Tp, _Alloc > & __list)
The forward_list assignment operator.
Parameters
__listβ aforward_listof identical element and allocator types.
All the elements of __list are copied.
Whether the allocator is copied depends on the allocator traits.
References forward_list(), std::__addressof(), assign(), and clear().
π₯ operator=(forward_list< _Tp, _Alloc > && __list) β the move assignment
template<typename _Tp, typename _Alloc = allocator<_Tp>> forward_list &
std::forward_list< _Tp, _Alloc >::operator= (forward_list< _Tp, _Alloc >
&& __list) [inline], [noexcept]
The forward_list move assignment operator.
Parameters
__listβ aforward_listof identical element and allocator types.
The contents of __list are moved into this forward_list (without copying, if the allocators permit it).
Afterwards __list is a valid, but unspecified forward_list. Read that again: valid but unspecified, so don't go assuming anything about its contents, okay? π
Whether the allocator is moved depends on the allocator traits.
πΈ operator=(std::initializer_list< _Tp > __il) β the curly-brace assignment
template<typename _Tp, typename _Alloc = allocator<_Tp>> forward_list &
std::forward_list< _Tp, _Alloc >::operator= (std::initializer_list< _Tp
> __il) [inline]
The forward_list initializer list assignment operator.
Parameters
__ilβ aninitializer_listofvalue_type.
Replaces the contents of the forward_list with copies of the elements in the initializer_list __il. This is linear in __il.size().
π¦ pop_front() β yeet the first element
template<typename _Tp, typename _Alloc = allocator<_Tp>> void
std::forward_list< _Tp, _Alloc >::pop_front () [inline]
Removes the first element. This is a typical stack operation. It shrinks the forward_list by one. Due to the nature of a forward_list, this operation can be done in constant time, and it only invalidates iterators/references to the element being removed.
π Note that no data is returned, and if the first element's data is needed, it should be retrieved before pop_front() is called. So grab it first, bestie, or it's gone forever. π
β push_front(const _Tp & __val) β add to the front
template<typename _Tp, typename _Alloc = allocator<_Tp>> void
std::forward_list< _Tp, _Alloc >::push_front (const _Tp & __val)
[inline]
Add data to the front of the forward_list.
Parameters
__valβ data to be added.
This is a typical stack operation. The function creates an element at the front of the forward_list and assigns the given data to it. Due to the nature of a forward_list, this operation can be done in constant time, and does not invalidate iterators and references. Chef's kiss. π
π§ remove(const _Tp & __val) β remove all elements equal to a value
template<typename _Tp, typename _Alloc> auto forward_list::remove (const _Tp
& __val)
Remove all elements equal to value.
Parameters
__valβ the value to remove.
remove() β last lil bit, bestie π
Removes every element in the list equal to __val. Remaining elements stay in list order. Note that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility. π€
References forward_list(), cbefore_begin(), get_allocator(), and splice_after().
remove_if()
template<typename _Tp, typename _Alloc> template<typename _Pred> auto
forward_list::remove_if (_Pred __pred) -> __remove_return_type
Remove all elements satisfying a predicate. So it's remove() but you get to be the judge, jury and vibe-checker. π
Parameters
__predβ Unary predicate function or object.
Removes every element in the list for which the predicate returns true. Remaining elements stay in list order. Note that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility. π
References forward_list(), cbefore_begin(), get_allocator(), and splice_after().
resize() β the one-arg era π
template<typename _Tp, typename _Alloc> void forward_list::resize (size_type
__sz)
Resizes the forward_list to the specified number of elements.
Parameters
__szβ Number of elements theforward_listshould contain.
This function will resize the forward_list to the specified number of elements. If the number is smaller than the forward_list's current number of elements the forward_list is truncated, otherwise the forward_list is extended and the new elements are default constructed. π±
References forward_list(), before_begin(), end(), and erase_after().
resize() β now with β¨dataβ¨
template<typename _Tp, typename _Alloc> void forward_list::resize (size_type
__sz, const value_type & __val)
Resizes the forward_list to the specified number of elements.
Parameters
__szβ Number of elements theforward_listshould contain.__valβ Data with which new elements should be populated.
This function will resize the forward_list to the specified number of elements. If the number is smaller than the forward_list's current number of elements the forward_list is truncated, otherwise the forward_list is extended and new elements are populated with given data. Same glow-up, but this time the newbies get fed actual values instead of vibes. π
References forward_list(), before_begin(), end(), erase_after(), and insert_after().
reverse()
template<typename _Tp, typename _Alloc = allocator<_Tp>> void
std::forward_list< _Tp, _Alloc >::reverse () [inline], [noexcept]
Reverse the elements in list. Reverse the order of elements in the list in linear time. the way it just flips the whole thing and stays noexcept?? obsessed. π
sort()
template<typename _Tp, typename _Alloc = allocator<_Tp>> void
std::forward_list< _Tp, _Alloc >::sort () [inline]
Sort the elements of the list. Sorts the elements of this list in NlogN time. Equivalent elements remain in list order. π¦
Referenced by std::forward_list< _Tp, polymorphic_allocator< _Tp > >::sort().
sort() β with a comparison function, the sequel πΈ
template<typename _Tp, class _Alloc> template<typename _Comp> void
forward_list::sort (_Comp __comp)
Sort the forward_list using a comparison function. Sorts the elements of this list in NlogN time. Equivalent elements remain in list order. π
References forward_list(), and empty().
splice_after() β rvalue range edition π§
template<typename _Tp, typename _Alloc = allocator<_Tp>> void
std::forward_list< _Tp, _Alloc >::splice_after (const_iterator __pos,
forward_list< _Tp, _Alloc > && , const_iterator __before, const_iterator
__last) [inline], [noexcept]
Insert range from another forward_list.
Parameters
__posβ Iterator referencing the element to insert after.__listβ Source list.__beforeβ Iterator referencing before the start of range in__list.__lastβ Iterator referencing the end of range in__list.
Removes elements in the range (__before,__last) and inserts them after __pos in constant time. π«
Undefined if__posis in(__before,__last). fr fr, do NOT do that, bestie. π
splice_after() β rvalue whole-list edition π
template<typename _Tp, typename _Alloc = allocator<_Tp>> void
std::forward_list< _Tp, _Alloc >::splice_after (const_iterator __pos,
forward_list< _Tp, _Alloc > && __list) [inline], [noexcept]
Insert contents of another forward_list.
Parameters
__posβ Iterator referencing the element to insert after.__listβ Source list.
The elements of list are inserted in constant time after the element referenced by pos. list becomes an empty list. π«
Requires this != &x. Like, actually requires it. Not a suggestion.
Referenced by remove(), remove_if(), std::forward_list< _Tp, polymorphic_allocator< _Tp > >::splice_after(), and unique().
splice_after() β single element edition π
template<typename _Tp, typename _Alloc> void forward_list::splice_after
(const_iterator __pos, forward_list< _Tp, _Alloc > && __list,
const_iterator __i) [noexcept]
Insert element from another forward_list.
Parameters
__posβ Iterator referencing the element to insert after.__listβ Source list.__iβ Iterator referencing the element before the element to move.
Removes the element in list __list referenced by __i and inserts it into the current list after __pos. πβ¨
References forward_list().
splice_after() β lvalue range edition π
template<typename _Tp, typename _Alloc = allocator<_Tp>> void
std::forward_list< _Tp, _Alloc >::splice_after (const_iterator __pos,
forward_list< _Tp, _Alloc > & , const_iterator __before, const_iterator
__last) [inline], [noexcept]
Insert range from another forward_list.
Parameters
__posβ Iterator referencing the element to insert after.__listβ Source list.__beforeβ Iterator referencing before the start of range in__list.__lastβ Iterator referencing the end of range in__list.
Removes elements in the range (__before,__last) and inserts them after __pos in constant time. π«
Undefined if__posis in(__before,__last). Same warning, same energy, still don't. π
swap()
template<typename _Tp, typename _Alloc = allocator<_Tp>> void
std::forward_list< _Tp, _Alloc >::swap (forward_list< _Tp, _Alloc > &
__list) [inline], [noexcept]
Swaps data with another forward_list.
Parameters
__listβ Aforward_listof the same element and allocator types.
This exchanges the elements between two lists in constant time. Note that the global std::swap() function is overloaded such that std::swap(l1, l2) will feed to this function. π
Whether the allocators are swapped depends on the allocator traits. iykyk, allocator traits are a whole personality.
unique() β no-args version π
template<typename _Tp, typename _Alloc = allocator<_Tp>>
__remove_return_type std::forward_list< _Tp, _Alloc >::unique ()
[inline]
Remove consecutive duplicate elements. For each consecutive set of elements with the same value, remove all but the first one. Remaining elements stay in list order. Note that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility. π
Referenced by std::forward_list< _Tp, polymorphic_allocator< _Tp > >::unique().
unique() β with a predicate π¦
template<typename _Tp, typename _Alloc> template<typename _BinPred> auto
forward_list::unique (_BinPred __binary_pred) -> __remove_return_type
Remove consecutive elements satisfying a predicate.
Parameters
__binary_predβ Binary predicate function or object.
For each consecutive set of elements [first,last) that satisfy predicate(first,i) where i is an iterator in [first,last), remove all but the first one. Remaining elements stay in list order. Note that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility. π€
References forward_list(), begin(), cbefore_begin(), end(), get_allocator(), and splice_after().
β¨ Author β¨
Generated automatically by Doxygen for libstdc++ from the source code. π€π
and that's a wrap on the whole std::forward_list page, bestie!! πππ credit where it's due: this iconic lil manpage is from libstdc++ (the source/version situation) and the page itself is titled std::forwa..., _Alloc >(3) β which is lowkey the funniest truncation ever, but we move. slay, go use your forward_list, and don't forget to manage your own pointers. periodt. π
β¨π
π¦ where this page comes from
- arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
- fedora 44: libstdc++-docs 16.2.1-2.fc44
- fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms