STD::LIST(3cxx)
π std::list< _Tp, _Alloc >(3cxx) β part 1 of 5 π
okay bestie, welcome to the <hotpink>std::list< _Tp, _Alloc >(3cxx)</hotpink> manual. This is the part where we meet the container, get the full synopsis, and go absolutely feral over every public type, public member function, protected type, protected member function, static protected member function, and protected attribute. No skipping, no summarizing, no "you get the idea" β we're doing all of it. π
πΈ NAME πΈ
std::list< _Tp, _Alloc > β a standard container with linear time access to elements, and fixed time insertion/deletion at any point in the sequence. It's giving "sequence container that knows what it is," fr fr. π¦
β¨ SYNOPSIS β¨
#include <list>
Inherits std::_List_base< _Tp, _Alloc >.
π Public Types π
typedef _Alloc allocator_typeβ the allocator type alias, exactly as written. no extra notes, just the typedef. π«Άtypedef _List_const_iterator< _Tp > const_iteratorβ const iterator type alias, periodt.typedef _Tp_alloc_traits::const_pointer const_pointerβ const pointer type alias, iconic.typedef _Tp_alloc_traits::const_reference const_referenceβ const reference type alias, no cap.typedef std::reverse_iterator< const_iterator > const_reverse_iteratorβ const reverse iterator type alias, slay.typedef ptrdiff_t difference_typeβ difference type alias, yes bestie.typedef _List_iterator< _Tp > iteratorβ iterator type alias, main character energy.typedef _Tp_alloc_traits::pointer pointerβ pointer type alias, lowkey essential.typedef _Tp_alloc_traits::reference referenceβ reference type alias, highkey essential.typedef std::reverse_iterator< iterator > reverse_iteratorβ reverse iterator type alias, we love to see it.typedef size_t size_typeβ size type alias, literally the size type.typedef _Tp value_typeβ value type alias, the whole vibe.
π Public Member Functions π
list ()=defaultβ creates a list with no elements. empty-list debut, no notes. β¨template<typename _InputIterator , typename = std::_RequireInputIter<_InputIterator>> list (_InputIterator __first, _InputIterator __last, const allocator_type &__a=allocator_type())β builds a list from a range. range-to-list pipeline, we love her. πlist (const allocator_type &__a) noexceptβ creates a list with no elements. allocator argument included, still no elements. πlist (const list &__x)β list copy constructor. copying the whole list vibe. π¦list (const list &__x, const __type_identity_t< allocator_type > &__a)β signature only, bestie. no extra description in the page.list (initializer_list< value_type > __l, const allocator_type &__a=allocator_type())β builds a list from aninitializer_list. cute little brace-list moment. πΈlist (list &&)=defaultβ list move constructor. moving, not copying, periodt. π₯list (list &&__x, const __type_identity_t< allocator_type > &__a) noexcept(_Node_alloc_traits::_S_always_equal())β signature only, no extra description here. thenoexceptis part of the package.list (size_type __n, const allocator_type &__a=allocator_type())β creates a list with default constructed elements.__nelements, default-constructed flavor. πlist (size_type __n, const value_type &__value, const allocator_type &__a=allocator_type())β creates a list with copies of an exemplar element. copies copies copies. π~list ()=defaultβ destructor, defaulted. bye bestie, cleanup time. π§template<typename _InputIterator , typename = std::_RequireInputIter<_InputIterator>> void assign (_InputIterator __first, _InputIterator __last)β assigns a range to a list. range assignment, slay. πvoid assign (initializer_list< value_type > __l)β assigns aninitializer_listto a list. brace-list assignment, iconic.void assign (size_type __n, const value_type &__val)β assigns a given value to a list.__ncopies of__val, no cap.const_reference back () const noexceptβ signature only, no extra notes. const back access, bestie.reference back () noexceptβ signature only, no extra notes. non-const back access, periodt.const_iterator begin () const noexceptβ signature only. const begin, we stan.iterator begin () noexceptβ signature only. non-const begin, main character.const_iterator cbegin () const noexceptβ signature only. const begin with thec, yes.const_iterator cend () const noexceptβ signature only. const end with thec, yes.void clear () noexceptβ signature only. clear the list, no extra description here.const_reverse_iterator crbegin () const noexceptβ signature only. const reverse begin, cute.const_reverse_iterator crend () const noexceptβ signature only. const reverse end, cute.template<typename... _Args> iterator emplace (const_iterator __position, _Args &&... __args)β constructs object in list before specified iterator. in-place construction moment, obsessed. π₯template<typename... _Args> reference emplace_back (_Args &&... __args)β signature only, no extra description. emplace at the back, we see you.template<typename... _Args> reference emplace_front (_Args &&... __args)β signature only, no extra description. emplace at the front, we see you too.bool empty () const noexceptβ signature only. empty check, no notes.const_iterator end () const noexceptβ signature only. const end, periodt.iterator end () noexceptβ signature only. non-const end, periodt.iterator erase (const_iterator __first, const_iterator __last) noexceptβ remove a range of elements. wipe the range, bestie. π«Άiterator erase (const_iterator __position) noexceptβ remove element at given position. one element, gone. πconst_reference front () const noexceptβ signature only. const front access, no extra notes.reference front () noexceptβ signature only. non-const front access, no extra notes.allocator_type get_allocator () const noexceptβ get a copy of the memory allocation object. allocator copy, slay. πiterator insert (const_iterator __p, initializer_list< value_type > __l)β inserts the contents of aninitializer_listinto list before specifiedconst_iterator. note the parameter is__p, bestie. πΈtemplate<typename _InputIterator , typename = std::_RequireInputIter<_InputIterator>> iterator insert (const_iterator __position, _InputIterator __first, _InputIterator __last)β inserts a range into the list. range insert, we love her.iterator insert (const_iterator __position, const value_type &__x)β inserts given value into list before specified iterator. one value, one position, iconic.iterator insert (const_iterator __position, size_type __n, const value_type &__x)β inserts a number of copies of given data into the list.__ncopies of__x, periodt.iterator insert (const_iterator __position, value_type &&__x)β inserts given rvalue into list before specified iterator. rvalue insert, no cap.size_type max_size () const noexceptβ signature only. max size, no extra notes.void merge (list &&__x)β merge sorted lists. rvalue-list merge, sorted-list business. π₯template<typename _StrictWeakOrdering > void merge (list &&__x, _StrictWeakOrdering __comp)β merge sorted lists according to comparison function. comparison function included, bestie.void merge (list &__x)β signature only. no extra description here, just the merge signature.template<typename _StrictWeakOrdering > void merge (list &__x, _StrictWeakOrdering __comp)β signature only. comparison-function merge, no extra notes.list & operator= (const list &__x)β list assignment operator. copy-assign the list, slay. πlist & operator= (initializer_list< value_type > __l)β list initializer list assignment operator. brace-list assignment operator, iconic.list & operator= (list &&__x) noexcept(_Node_alloc_traits::_S_nothrow_move())β list move assignment operator. move-assign with thenoexceptspelling exactly as written. π₯void pop_back () noexceptβ removes last element. bye-bye back element. π¦void pop_front () noexceptβ removes first element. bye-bye front element. π¦void push_back (const value_type &__x)β add data to the end of the list. back-of-the-line behavior, we stan.void push_back (value_type &&__x)β signature only, no extra description. rvalue push-back, we see you.void push_front (const value_type &__x)β add data to the front of the list. front-of-the-line behavior, main character.void push_front (value_type &&__x)β signature only, no extra description. rvalue push-front, we see you too.const_reverse_iterator rbegin () const noexceptβ signature only. const reverse begin, no notes.reverse_iterator rbegin () noexceptβ signature only. non-const reverse begin, no notes.__remove_return_type remove (const _Tp &__value)β remove all elements equal to value. all of them, bestie. πtemplate<typename _Predicate > __remove_return_type remove_if (_Predicate)β remove all elements satisfying a predicate. predicate-driven removal, periodt.const_reverse_iterator rend () const noexceptβ signature only. const reverse end, no extra notes.reverse_iterator rend () noexceptβ signature only. non-const reverse end, no extra notes.void resize (size_type __new_size)β resizes the list to the specified number of elements. new size, new vibe. πvoid resize (size_type __new_size, const value_type &__x)β resizes the list to the specified number of elements.__xis in the signature, so there's that. πΈvoid reverse () noexceptβ reverse the elements in list. flip the whole list, iconic. πsize_type size () const noexceptβ signature only. size check, no extra notes.void sort ()β sort the elements. sorted-list era, we love to see it. πtemplate<typename _StrictWeakOrdering > void sort (_StrictWeakOrdering)β sort the elements according to comparison function. comparison function sort, slay.void splice (const_iterator __position, list &&__x) noexceptβ insert contents of another list. splice the whole rvalue list, no cap. π₯void splice (const_iterator __position, list &&__x, const_iterator __first, const_iterator __last) noexceptβ insert range from another list. rvalue list, range splice, periodt.void splice (const_iterator __position, list &&__x, const_iterator __i) noexceptβ insert element from another list. rvalue list, single-element splice, iconic.void splice (const_iterator __position, list &__x) noexceptβ signature only. no extra description here, just the splice signature.void splice (const_iterator __position, list &__x, const_iterator __first, const_iterator __last) noexceptβ insert range from another list. range splice, bestie.void splice (const_iterator __position, list &__x, const_iterator __i) noexceptβ insert element from another list. single-element splice, bestie.void swap (list &__x) noexceptβ swaps data with another list. swap era, we love her. π«Ά__remove_return_type unique ()β remove consecutive duplicate elements. consecutive duplicates, not all duplicates β that's the wording, bestie. πtemplate<typename _BinaryPredicate > __remove_return_type unique (_BinaryPredicate)β remove consecutive elements satisfying a predicate. predicate in the mix, periodt.
π§ Protected Types π§
typedef _List_node< _Tp > _Nodeβ protected type alias, exactly as written. internals moment, iykyk. π
π¦ Protected Member Functions π¦
these are the protected-guts functions, bestie. the page gives the signatures and not much extra commentary on each, so we're keeping it exact and keeping it cute.
template<typename _InputIterator > void _M_assign_dispatch (_InputIterator __first, _InputIterator __last, __false_type)β signature only, no extra notes.template<typename _Integer > void _M_assign_dispatch (_Integer __n, _Integer __val, __true_type)β signature only, no extra notes.void _M_check_equal_allocators (const list &__x) noexceptβ signature only, no extra notes.void _M_clear () noexceptβ signature only, no extra notes.template<typename... _Args> _Node * _M_create_node (_Args &&... __args)β signature only, no extra notes.void _M_dec_size (size_t)β signature only, no extra notes.void _M_default_append (size_type __n)β signature only, no extra notes.void _M_default_initialize (size_type __n)β signature only, no extra notes.size_t _M_distance (const void *, const void *) constβ signature only, no extra notes.void _M_erase (iterator __position) noexceptβ signature only, no extra notes.void _M_fill_assign (size_type __n, const value_type &__val)β signature only, no extra notes.void _M_fill_initialize (size_type __n, const value_type &__x)β signature only, no extra notes._Node_alloc_traits::pointer _M_get_node ()β signature only, no extra notes.const _Node_alloc_type & _M_get_Node_allocator () const noexceptβ signature only, no extra notes. yes, theNin_M_get_Node_allocatoris capital, keep it exact._Node_alloc_type & _M_get_Node_allocator () noexceptβ signature only, no extra notes.size_t _M_get_size () constβ signature only, no extra notes.void _M_inc_size (size_t)β signature only, no extra notes.void _M_init () noexceptβ signature only, no extra notes.template<typename _InputIterator > void _M_initialize_dispatch (_InputIterator __first, _InputIterator __last, __false_type)β signature only, no extra notes.template<typename _Integer > void _M_initialize_dispatch (_Integer __n, _Integer __x, __true_type)β signature only, no extra notes.template<typename... _Args> void _M_insert (iterator __position, _Args &&... __args)β signature only, no extra notes.void _M_move_assign (list &&__x, false_type)β signature only, no extra notes.void _M_move_assign (list &&__x, true_type) noexceptβ signature only, no extra notes.void _M_move_nodes (_List_base &&__x)β signature only, no extra notes.size_t _M_node_count () constβ signature only, no extra notes.void _M_put_node (typename _Node_alloc_traits::pointer __p) noexceptβ signature only, no extra notes.const_iterator _M_resize_pos (size_type &__new_size) constβ signature only, no extra notes.void _M_set_size (size_t)β signature only, no extra notes.void _M_transfer (iterator __position, iterator __first, iterator __last)β signature only, no extra notes.
β Static Protected Member Functions β
static size_t _S_distance (const __detail::_List_node_base *__first, const __detail::_List_node_base *__last)β static protected signature only, no extra notes. πstatic size_t _S_distance (const_iterator, const_iterator)β second_S_distanceoverload, signature only, no extra notes. πΈ
π Protected Attributes π
_List_impl _M_implβ protected attribute, exactly as written. internals staying internal, periodt. π
π Detailed Description π
template<typename _Tp, typename _Alloc = std::allocator<_Tp>> class std::list< _Tp, _Alloc >
A standard container with linear time access to elements, and fixed time insertion/deletion at any point in the sequence. Bestie, itβs giving βlinked list main character energyβ for real π
πΈ Template Parameters πΈ
_Tpβ Type of element._Allocβ Allocator type, defaults toallocator<_Tp>.
Meets the requirements of a container, a reversible container, and a sequence, including the optional sequence requirements with the exception of at and operator[].
This is a doubly linked list. Traversal up and down 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::list provides specialized algorithms unique to linked lists, such as splicing, sorting, and in-place reversal. Iconic behavior, no cap β¨
A couple points on memory allocation for list<Tp>:
First, we never actually allocate a Tp, we allocate List_node<Tp>'s and trust [20.1.5]/4 to DTRT. This is to ensure that after elements from list<X,Alloc1> are spliced into list<X,Alloc2>, destroying the memory of the second list is a valid operation, i.e., Alloc1 giveth and Alloc2 taketh away.
Second, a list conceptually represented as
A <---> B <---> C <---> D
is actually circular; a link exists between A and D. The list class holds (as its only data member) a private list::iterator pointing to D, not to A! To get to the head of the list, we start at the tail and move forward by one. When this member iterator's next/previous pointers refer to itself, the list is empty. Lowkey circular royalty ππ
β¨ Constructor & Destructor Documentation β¨
π std::list< _Tp, _Alloc >::list () [default]
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> std::list< _Tp, _Alloc >::list () [default]
Creates a list with no elements. Empty-list era π«Ά
π std::list< _Tp, _Alloc >::list (const allocator_type & __a) [inline], [explicit], [noexcept]
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> std::list< _Tp, _Alloc >::list (const allocator_type & __a) [inline], [explicit], [noexcept]
Creates a list with no elements.
Parameters
__aβ An allocator object.
π std::list< _Tp, _Alloc >::list (size_type __n, const allocator_type & __a = allocator_type()) [inline], [explicit]
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> std::list< _Tp, _Alloc >::list (size_type __n, const allocator_type & __a = allocator_type()) [inline], [explicit]
Creates a list with default constructed elements.
Parameters
__nβ The number of elements to initially create.__aβ An allocator object.
This constructor fills the list with __n default constructed elements.
π std::list< _Tp, _Alloc >::list (size_type __n, const value_type & __value, const allocator_type & __a = allocator_type()) [inline]
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> std::list< _Tp, _Alloc >::list (size_type __n, const value_type & __value, const allocator_type & __a = allocator_type()) [inline]
Creates a list with copies of an exemplar element.
Parameters
__nβ The number of elements to initially create.__valueβ An element to copy.__aβ An allocator object.
This constructor fills the list with __n copies of __value.
π std::list< _Tp, _Alloc >::list (const list< _Tp, _Alloc > & __x) [inline]
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> std::list< _Tp, _Alloc >::list (const list< _Tp, _Alloc > & __x) [inline]
List copy constructor.
Parameters
__xβ A list of identical element and allocator types.
The newly-created list uses a copy of the allocation object used by __x (unless the allocator traits dictate a different object).
References std::list< _Tp, _Alloc >::begin(), and std::list< _Tp, _Alloc >::end().
π std::list< _Tp, _Alloc >::list (list< _Tp, _Alloc > &&) [default]
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> std::list< _Tp, _Alloc >::list (list< _Tp, _Alloc > &&) [default]
List move constructor. The newly-created list contains the exact contents of the moved instance. The contents of the moved instance are a valid, but unspecified list.
π std::list< _Tp, _Alloc >::list (initializer_list< value_type > __l, const allocator_type & __a = allocator_type()) [inline]
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> std::list< _Tp, _Alloc >::list (initializer_list< value_type > __l, const allocator_type & __a = allocator_type()) [inline]
Builds a list from an initializer_list.
Parameters
__lβ An initializer_list of value_type.__aβ An allocator object.
Create a list consisting of copies of the elements in the initializer_list __l. This is linear in __l.size().
π std::list< _Tp, _Alloc >::list (_InputIterator __first, _InputIterator __last, const allocator_type & __a = allocator_type()) [inline]
template<typename _Tp , typename _Alloc = std::allocator<_Tp>>
template<typename _InputIterator , typename = std::_RequireInputIter<_InputIterator>> std::list< _Tp, _Alloc >::list (_InputIterator __first, _InputIterator __last, const allocator_type & __a = allocator_type()) [inline]
Builds a list from a range.
Parameters
__firstβ An input iterator.__lastβ An input iterator.__aβ An allocator object.
Create a list consisting of copies of the elements from [__first,__last). This is linear in N (where N is distance(__first,__last)).
π std::list< _Tp, _Alloc >::~list () [default]
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> std::list< _Tp, _Alloc >::~list () [default]
No explicit dtor needed as the _Base dtor takes care of things. The _Base dtor only erases the elements, and note 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. π«‘
π¦ Member Function Documentation π¦
π std::list< _Tp, _Alloc >::_M_create_node (_Args &&... __args) [inline], [protected]
template<typename _Tp , typename _Alloc = std::allocator<_Tp>>
template<typename... _Args> _Node * std::list< _Tp, _Alloc >::_M_create_node (_Args &&... __args) [inline], [protected]
Parameters
__argsβ An instance of user data.
Allocates space for a new node and constructs a copy of __args in it.
π std::list< _Tp, _Alloc >::assign (_InputIterator __first, _InputIterator __last) [inline]
template<typename _Tp , typename _Alloc = std::allocator<_Tp>>
template<typename _InputIterator , typename = std::_RequireInputIter<_InputIterator>> void std::list< _Tp, _Alloc >::assign (_InputIterator __first, _InputIterator __last) [inline]
Assigns a range to a list.
Parameters
__firstβ An input iterator.__lastβ An input iterator.
This function fills a list with copies of the elements in the range [__first,__last).
Note that the assignment completely changes the list and that the resulting list's size is the same as the number of elements assigned.
π std::list< _Tp, _Alloc >::assign (initializer_list< value_type > __l) [inline]
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> void std::list< _Tp, _Alloc >::assign (initializer_list< value_type > __l) [inline]
Assigns an initializer_list to a list.
Parameters
__lβ An initializer_list of value_type.
Replace the contents of the list with copies of the elements in the initializer_list __l. This is linear in __l.size().
π std::list< _Tp, _Alloc >::assign (size_type __n, const value_type & __val) [inline]
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> void std::list< _Tp, _Alloc >::assign (size_type __n, const value_type & __val) [inline]
Assigns a given value to a list.
Parameters
__nβ Number of elements to be assigned.__valβ Value to be assigned.
This function fills a list with __n copies of the given value. Note that the assignment completely changes the list and that the resulting list's size is the same as the number of elements assigned.
Referenced by std::list< _Tp, _Alloc >::operator=().
π std::list< _Tp, _Alloc >::back () const [inline], [noexcept]
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> const_reference std::list< _Tp, _Alloc >::back () const [inline], [noexcept]
Returns a read-only (constant) reference to the data at the last element of the list.
References std::list< _Tp, _Alloc >::end().
π std::list< _Tp, _Alloc >::back () [inline], [noexcept]
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> reference std::list< _Tp, _Alloc >::back () [inline], [noexcept]
Returns a read/write reference to the data at the last element of the list.
References std::list< _Tp, _Alloc >::end().
π std::list< _Tp, _Alloc >::begin () const [inline], [noexcept]
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> const_iterator std::list< _Tp, _Alloc >::begin () const [inline], [noexcept]
Returns a read-only (constant) iterator that points to the first element in the list. Iteration is done in ordinary element order.
π std::list< _Tp, _Alloc >::begin () [inline], [noexcept]
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> iterator std::list< _Tp, _Alloc >::begin () [inline], [noexcept]
Returns a read/write iterator that points to the first element in the list. Iteration is done in ordinary element order.
Referenced by std::list< _Tp, _Alloc >::list(), std::list< _Tp, _Alloc >::crend(), std::list< _Tp, _Alloc >::front(), std::list< _Tp, _Alloc >::front(), std::list< _Tp, _Alloc >::insert(), std::list< _Tp, _Alloc >::insert(), std::list< _Tp, _Alloc >::merge(), std::list< _Tp, _Alloc >::merge(), std::operator<=>(), std::list< _Tp, _Alloc >::operator=(), std::list< _Tp, _Alloc >::pop_front(), std::list< _Tp, _Alloc >::push_front(), std::list< _Tp, _Alloc >::remove(), std::list< _Tp, _Alloc >::remove_if(), std::list< _Tp, _Alloc >::rend(), std::list< _Tp, _Alloc >::rend(), std::list< _Tp, _Alloc >::splice(), std::list< _Tp, _Alloc >::unique(), and std::list< _Tp, _Alloc >::unique().
π std::list< _Tp, _Alloc >::cbegin () const [inline], [noexcept]
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> const_iterator std::list< _Tp, _Alloc >::cbegin () const [inline], [noexcept]
Returns a read-only (constant) iterator that points to the first element in the list. Iteration is done in ordinary element order.
π std::list< _Tp, _Alloc >::cend () const [inline], [noexcept]
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> const_iterator std::list< _Tp, _Alloc >::cend () const [inline], [noexcept]
Returns a read-only (constant) iterator that points one past the last element in the list. Iteration is done in ordinary element order.
π std::list< _Tp, _Alloc >::clear () [inline], [noexcept]
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> void std::list< _Tp, _Alloc >::clear () [inline], [noexcept]
Erases all the elements. 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. π«Ά
π std::list< _Tp, _Alloc >::crbegin () const [inline], [noexcept]
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> const_reverse_iterator std::list< _Tp, _Alloc >::crbegin () const [inline], [noexcept]
Returns a read-only (constant) reverse iterator that points to the last element in the list. Iteration is done in reverse element order.
References std::list< _Tp, _Alloc >::end().
π std::list< _Tp, _Alloc >::crend () const [inline], [noexcept]
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> const_reverse_iterator std::list< _Tp, _Alloc >::crend () const [inline], [noexcept]
Returns a read-only (constant) reverse iterator that points to one before the first element in the list. Iteration is done in reverse element order.
References std::list< _Tp, _Alloc >::begin().
π list::emplace (const_iterator __position, _Args &&... __args)
template<typename _Tp, typename _Alloc > template<typename... _Args> list< _Tp, _Alloc >::iterator list::emplace (const_iterator __position, _Args &&... __args)
Constructs object in list before specified iterator.
Parameters
__positionβ A const_iterator into the list.__argsβ Arguments.
Returns
An iterator that points to the inserted data.
Okay so this function is gonna insert an object of type T constructed with T(std::forward<Args>(args)...) right before the location you specify. And because it's a list β its whole thing β this happens in constant time, and it does not invalidate iterators and references. Nobody gets evicted. π
Referenced by std::list< _Tp, _Alloc >::insert().
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> bool std::list< _Tp, _Alloc >::empty () const [inline], [noexcept]
Returns true if the list is empty. (So like, begin() would equal end() β that's the vibe check for "nobody's home". π«₯)
Referenced by std::list< _Tp, _Alloc >::insert(), and std::list< _Tp, _Alloc >::splice().
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> const_iterator std::list< _Tp, _Alloc >::end () const [inline], [noexcept]
Returns a read-only (constant) iterator that points one past the last element in the list. Iteration happens in ordinary element order, bestie. β
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> iterator std::list< _Tp, _Alloc >::end () [inline], [noexcept]
Returns a read/write iterator that points one past the last element in the list. Iteration is done in ordinary element order. Same as the const one but it'll let you touch stuff. π
Referenced by std::list< _Tp, _Alloc >::list(), std::list< _Tp, _Alloc >::back(), std::list< _Tp, _Alloc >::back(), std::list< _Tp, _Alloc >::crbegin(), std::list< _Tp, _Alloc >::merge(), std::list< _Tp, _Alloc >::merge(), std::operator<=>(), std::list< _Tp, _Alloc >::operator=(), std::list< _Tp, _Alloc >::push_back(), std::list< _Tp, _Alloc >::rbegin(), std::list< _Tp, _Alloc >::rbegin(), and std::list< _Tp, _Alloc >::splice().
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> iterator std::list< _Tp, _Alloc >::erase (const_iterator __first, const_iterator __last) [inline], [noexcept]
Remove a range of elements. Like a clean sweep, but make it surgical bestie π§Ήβ¨
Parameters
__firstβ Iterator pointing to the first element to be erased.__lastβ Iterator pointing to one past the last element to be erased.
Returns β An iterator pointing to the element pointed to by last prior to erasing (or end()).
This function will erase the elements in the range [first,last) and shorten the list accordingly.
Lowkey important: this operation is linear time in the size of the range, and it only invalidates iterators/references to the element being removed. Also, heads up (the docs literally caution you): this function only erases the elements β if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is your responsibility. No take-backs, no cleanup on our end. π
References std::list< _Tp, _Alloc >::erase().
template<typename _Tp , typename _Alloc > list< _Tp, _Alloc >::iterator list::erase (const_iterator __position) [noexcept]
Remove the element at the given position. One (1) element. Bye π
Parameters
__positionβ Iterator pointing to element to be erased.
Returns β An iterator pointing to the next element (or end()).
This function will erase the element at the given position and thus shorten the list by one.
Due to the nature of a list this operation can be done in constant time, and only invalidates iterators/references to the element being removed. And again, the caution: this function only erases the element, and 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. π«‘
Referenced by std::list< _Tp, _Alloc >::erase().
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> const_reference std::list< _Tp, _Alloc >::front () const [inline], [noexcept]
Returns a read-only (constant) reference to the data at the first element of the list. Peek at the main character, don't touch. π
References std::list< _Tp, _Alloc >::begin().
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> reference std::list< _Tp, _Alloc >::front () [inline], [noexcept]
Returns a read/write reference to the data at the first element of the list. Now you can touch it. π
References std::list< _Tp, _Alloc >::begin().
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> allocator_type std::list< _Tp, _Alloc >::get_allocator () const [inline], [noexcept]
Get a copy of the memory allocation object. That's it, that's the whole function. π
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> iterator std::list< _Tp, _Alloc >::insert (const_iterator __p, initializer_list< value_type > __l) [inline]
Inserts the contents of an initializer_list into the list before the specified const_iterator.
Parameters
__pβ Aconst_iteratorinto the list.__lβ Aninitializer_listofvalue_type.
Returns β An iterator pointing to the first element inserted (or __position).
This function will insert copies of the data in the initializer_list l into the list before the location specified by p.
This operation is linear in the number of elements inserted and does not invalidate iterators and references. Slay, no collateral damage. β¨
References std::list< _Tp, _Alloc >::insert().
template<typename _Tp , typename _Alloc > template<typename _InputIterator , typename > list< _Tp, _Alloc >::iterator list::insert (const_iterator __position, _InputIterator __first, _InputIterator __last)
Inserts a range into the list.
Parameters
__positionβ Aconst_iteratorinto the list.__firstβ An input iterator.__lastβ An input iterator.
Returns β An iterator pointing to the first element inserted (or __position).
This function will insert copies of the data in the range [first,last) into the list before the location specified by position.
This operation is linear in the number of elements inserted and does not invalidate iterators and references. π¦
References std::list< _Tp, _Alloc >::begin(), and std::list< _Tp, _Alloc >::empty().
template<typename _Tp , typename _Alloc > list< _Tp, _Alloc >::iterator list::insert (const_iterator __position, const value_type & __x)
Inserts the given value into the list before the specified iterator.
Parameters
__positionβ Aconst_iteratorinto the list.__xβ Data to be inserted.
Returns β An iterator that points to the inserted data.
This function will insert a copy of the given value before the specified location. Due to the nature of a list this operation can be done in constant time, and does not invalidate iterators and references. Obsessed with the efficiency fr fr. π₯
Referenced by std::list< _Tp, _Alloc >::insert().
template<typename _Tp , typename _Alloc > list< _Tp, _Alloc >::iterator list::insert (const_iterator __position, size_type __n, const value_type & __x)
Inserts a number of copies of the given data into the list.
Parameters
__positionβ Aconst_iteratorinto the list.__nβ Number of elements to be inserted.__xβ Data to be inserted.
Returns β An iterator pointing to the first element inserted (or __position).
This function will insert a specified number of copies of the given data before the location specified by position.
This operation is linear in the number of elements inserted and does not invalidate iterators and references. π
References std::list< _Tp, _Alloc >::begin().
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> iterator std::list< _Tp, _Alloc >::insert (const_iterator __position, value_type && __x) [inline]
Inserts the given rvalue into the list before the specified iterator. Move semantics moment π«
Parameters
__positionβ Aconst_iteratorinto the list.__xβ Data to be inserted.
Returns β An iterator that points to the inserted data.
This function will insert a copy of the given rvalue before the specified location. Due to the nature of a list this operation can be done in constant time, and does not invalidate iterators and references.
References std::list< _Tp, _Alloc >::emplace(), and std::move().
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> size_type std::list< _Tp, _Alloc >::max_size () const [inline], [noexcept]
Returns the size() of the largest possible list. Like, the absolute max. The final boss ceiling. π
References __gnu_cxx::__alloc_traits< _Alloc, typename >::max_size().
template<typename _Tp , typename _Alloc > void list::merge (list< _Tp, _Alloc > && __x)
Merge sorted lists. It's giving collab. π€
Parameters
__xβ Sorted list to merge.
Assumes that both __x and this list are sorted according to operator<(). Merges elements of __x into this list in sorted order, leaving __x empty when complete. Elements in this list precede elements in __x that are equal.
References std::__addressof(), std::list< _Tp, _Alloc >::begin(), std::begin(), std::list< _Tp, _Alloc >::end(), and std::end().
template<typename _Tp , typename _Alloc > template<typename _StrictWeakOrdering > void list::merge (list< _Tp, _Alloc > && __x, _StrictWeakOrdering __comp)
Merge sorted lists according to a comparison function. Custom sort order, custom vibes. π
Template Parameters
_StrictWeakOrderingβ Comparison function defining sort order.
Parameters
__xβ Sorted list to merge.__compβ Comparison functor.
Assumes that both __x and this list are sorted according to StrictWeakOrdering. Merges elements of __x into this list in sorted order, leaving __x empty when complete. Elements in this list precede elements in __x that are equivalent according to StrictWeakOrdering().
References std::__addressof(), std::list< _Tp, _Alloc >::begin(), std::begin(), std::list< _Tp, _Alloc >::end(), and std::end().
template<typename _Tp , typename _Alloc > list< _Tp, _Alloc > & list::operator= (const list< _Tp, _Alloc > & __x)
List assignment operator. Copy-paste energy but make it official. π
Parameters
__xβ A list of identical element and allocator types.
All the elements of __x are copied.
Whether the allocator is copied depends on the allocator traits. (iykyk β it's a traits thing, don't @ me.)
References std::__addressof(), std::list< _Tp, _Alloc >::begin(), and std::list< _Tp, _Alloc >::end().
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> list & std::list< _Tp, _Alloc >::operator= (initializer_list< value_type > __l) [inline]
List initializer list assignment operator. Curly braces to the rescue π
Parameters
__lβ Aninitializer_listofvalue_type.
Replace the contents of the list with copies of the elements in the initializer_list __l. This is linear in l.size().
References std::list< _Tp, _Alloc >::assign().
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> list & std::list< _Tp, _Alloc >::operator= (list< _Tp, _Alloc > && __x) [inline], [noexcept]
List move assignment operator. No copying, we're stealing (consensually). πββοΈπ¨
Parameters
__xβ A list of identical element and allocator types.
The contents of __x are moved into this list (without copying).
Afterwards __x is a valid, but unspecified list. β οΈ Like, it exists, it's fine, but don't expect it to still have its old stuff, bestie.
Whether the allocator is moved depends on the allocator traits.
References std::move().
π
pop_back()
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> void
std::list< _Tp, _Alloc >::pop_back () [inline], [noexcept]
Okay so bestie, this one removes the last element. It's a classic stack move β the list just shrinks by one. And because lists are built different (linked nodes, no shifting around), this is a constant time operation, and it only invalidates iterators/references to the element that's literally being yeeted. Nothing else gets touched, periodt.
β οΈ Heads up: no data comes back out of this. If you actually need the last element's data, grab it before you call pop_back(). The function does not hand it to you, no cap.
π«Ά pop_front()
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> void
std::list< _Tp, _Alloc >::pop_front () [inline], [noexcept]
Same vibe, opposite end β removes the first element. Also a typical stack operation, also shrinks the list by one, also constant time, and again only the iterators/references to the element being removed get invalidated. Iconic.
β οΈ Same warning as its twin: no data is returned. If you need the first element's data, get it before calling pop_front(). π
References std::list< _Tp, _Alloc >::begin().
π push_back()
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> void
std::list< _Tp, _Alloc >::push_back (const value_type & __x) [inline]
Adds data to the end of the list. Classic stack behaviour, we love to see it β¨.
__xβ the data to be added.
So what happens: the function creates an element at the end of the list and assigns your data to it. Since it's a list, this is constant time, and it does not invalidate iterators and references. Your other iterators stay valid and unbothered, main character energy only.
References std::list< _Tp, _Alloc >::end().
πΈ push_front()
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> void
std::list< _Tp, _Alloc >::push_front (const value_type & __x) [inline]
Adds data to the front of the list β the VIP entrance π .
__xβ the data to be added.
Typical stack operation: creates an element at the front, assigns the given data to it, constant time, and does not invalidate iterators and references. Chef's kiss.
References std::list< _Tp, _Alloc >::begin().
π¦ rbegin() const
template<typename _Tp , typename _Alloc = std::allocator<_Tp>>
const_reverse_iterator std::list< _Tp, _Alloc >::rbegin () const
[inline], [noexcept]
Returns a read-only (constant) reverse iterator pointing at the last element in the list. Iteration happens in reverse element order β going backwards but make it fashion π.
References std::list< _Tp, _Alloc >::end().
π¦ rbegin()
template<typename _Tp , typename _Alloc = std::allocator<_Tp>>
reverse_iterator std::list< _Tp, _Alloc >::rbegin () [inline],
[noexcept]
The non-const twin: returns a read/write reverse iterator pointing at the last element. Iteration is done in reverse element order. Same energy, but you can write through this one π₯.
References std::list< _Tp, _Alloc >::end().
π remove()
template<typename _Tp , typename _Alloc > list< _Tp, _Alloc
>::__remove_return_type list::remove (const _Tp & __value)
Removes all elements equal to __value. All of them. Not just the first one. It's giving thorough π§Ή.
__valueβ the value to remove.
Every element in the list equal to value gets erased, and the remaining elements stay in list order (no shuffling, no chaos).
β οΈ Real talk: this function only erases the elements. If the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility β that's you, bestie. π
References std::list< _Tp, _Alloc >::begin(), std::begin(), std::end(), std::list< _Tp, _Alloc >::size(), and std::list< _Tp, _Alloc >::splice().
π§ remove_if()
template<typename _Tp , typename _Alloc > template<typename _Predicate >
list< _Tp, _Alloc >::__remove_return_type list::remove_if (_Predicate
__pred)
Removes every element that satisfies your predicate. You decide the vibe check, the list enforces it β¨.
Template Parameters
_Predicateβ unary predicate function or object.
Every element in the list for which the predicate returns true gets removed, and the remaining elements stay in list order.
β οΈ Same caveat as remove(): this only erases the elements. If the elements are pointers, the pointed-to memory is not touched in any way, and managing the pointer is the user's responsibility. No freebies here π.
References std::list< _Tp, _Alloc >::begin(), std::begin(), std::end(), std::list< _Tp, _Alloc >::size(), and std::list< _Tp, _Alloc >::splice().
π¦ rend() const
template<typename _Tp , typename _Alloc = std::allocator<_Tp>>
const_reverse_iterator std::list< _Tp, _Alloc >::rend () const [inline],
[noexcept]
Returns a read-only (constant) reverse iterator that points to one before the first element in the list. Iteration is done in reverse element order. It's the reverse-end marker, the "you've gone too far backwards, babe" signpost π.
References std::list< _Tp, _Alloc >::begin().
π¦ rend()
template<typename _Tp , typename _Alloc = std::allocator<_Tp>>
reverse_iterator std::list< _Tp, _Alloc >::rend () [inline], [noexcept]
Returns a read/write reverse iterator that points to one before the first element in the list, with iteration in reverse element order. Same spot, but writable π .
References std::list< _Tp, _Alloc >::begin().
π resize()
template<typename _Tp , typename _Alloc > void list::resize (size_type
__new_size)
Resizes the list to the specified number of elements. Glow-up or shrink-down, your call π.
__new_sizeβ number of elements the list should contain.
If __new_size is smaller than the list's current size, the list is truncated. Otherwise, default constructed elements are appended. That's the whole tea.
References std::end().
π resize() (with a value)
template<typename _Tp , typename _Alloc > void list::resize (size_type
__new_size, const value_type & __x)
Same resize, but you get to pick what the new elements are filled with. No default-constructed randos here β¨.
__new_sizeβ number of elements the list should contain.__xβ data with which new elements should be populated.
If __new_size is smaller than the current size, the list is truncated. Otherwise the list is extended and the new elements are populated with the given data. Custom fit, obsessed.
References std::end().
π₯ reverse()
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> void
std::list< _Tp, _Alloc >::reverse () [inline], [noexcept]
Reverses the elements in the list β flips the whole order in linear time. It's giving "turn the car around" ππ¨.
β size() const
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> size_type
std::list< _Tp, _Alloc >::size () const [inline], [noexcept]
Returns the number of elements in the list. Simple, honest, reliable β the friend who tells you how many people are actually coming to the party π .
Referenced by std::operator<=>(), std::list< _Tp, _Alloc >::remove(), std::list< _Tp, _Alloc >::remove_if(), std::list< _Tp, _Alloc >::unique(), and std::list< _Tp, _Alloc >::unique().
π sort()
template<typename _Tp , typename _Alloc > void list::sort ()
Sorts the elements of this list in NlogN time. Equivalent elements remain in list order β so it's stable, we love a stable icon β¨.
References std::begin(), std::empty(), and std::end().
π sort() with a comparator
template<typename _Tp , typename _Alloc > template<typename
_StrictWeakOrdering > void list::sort (_StrictWeakOrdering __comp)
Sorts the elements according to your comparison function. Also NlogN time, and equivalent elements remain in list order. You bring the rules, the list brings the order π.
References std::begin(), std::empty(), and std::end().
π§ splice() β whole list, move
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> void
std::list< _Tp, _Alloc >::splice (const_iterator __position, list< _Tp,
_Alloc > && __x) [inline], [noexcept]
Inserts the contents of another list. It's a whole-list transplant, and it's constant time β no copying, just re-linking nodes π₯.
__positionβ iterator referencing the element to insert before.__xβ source list.
The elements of __x are inserted in constant time in front of the element referenced by __position. Afterwards, __x becomes an empty list.
β οΈ Requires this != __x. Splicing a list into itself is a no-go, don't even try it π.
References std::list< _Tp, _Alloc >::begin(), std::list< _Tp, _Alloc >::empty(), and std::list< _Tp, _Alloc >::end().
Referenced by std::list< _Tp, _Alloc >::remove(), std::list< _Tp, _Alloc >::remove_if(), std::list< _Tp, _Alloc >::splice(), std::list< _Tp, _Alloc >::splice(), std::list< _Tp, _Alloc >::unique(), and std::list< _Tp, _Alloc >::unique().
π§ splice() β range, move
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> void
std::list< _Tp, _Alloc >::splice (const_iterator __position, list< _Tp,
_Alloc > && __x, const_iterator __first, const_iterator __last)
[inline], [noexcept]
Inserts a range from another list. Selective relocation, we stan π.
__positionβ const_iterator referencing the element to insert before.__xβ source list.__firstβ const_iterator referencing the start of the range inx.__lastβ const_iterator referencing the end of the range inx.
Removes the elements in the range [__first,__last) and inserts them before __position in constant time.
β οΈ Undefined if__positionis in[__first,__last). Like, literally undefined behaviour. Do not. π
References std::__addressof().
π§ splice() β single element, move
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> void
std::list< _Tp, _Alloc >::splice (const_iterator __position, list< _Tp,
_Alloc > && __x, const_iterator __i) [inline], [noexcept]
Inserts one element from another list. Single-node teleportation β¨.
__positionβ const_iterator referencing the element to insert before.__xβ source list.__iβ const_iterator referencing the element to move.
Removes the element in list __x referenced by __i and inserts it into the current list before __position.
References std::__addressof().
π§ splice() β range, copy-list reference
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> void
std::list< _Tp, _Alloc >::splice (const_iterator __position, list< _Tp,
_Alloc > & __x, const_iterator __first, const_iterator __last) [inline],
[noexcept]
Inserts a range from another list, taking the source list by lvalue reference this time π«Ά.
__positionβ const_iterator referencing the element to insert before.__xβ source list.__firstβ const_iterator referencing the start of the range inx.__lastβ const_iterator referencing the end of the range inx.
Removes the elements in the range [__first,__last) and inserts them before __position in constant time.
β οΈ Again: undefined if__positionis in[__first,__last). Respect the range, bestie π.
References std::move(), and std::list< _Tp, _Alloc >::splice().
π§ splice() β single element, copy-list reference
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> void
std::list< _Tp, _Alloc >::splice (const_iterator __position, list< _Tp,
_Alloc > & __x, const_iterator __i) [inline], [noexcept]
Inserts one element from another list, source taken by lvalue reference β the single-element sibling of the one above π .
__positionβ const_iterator referencing the element to insert before.__xβ source list.__iβ const_iterator referencing the element to move.
Removes the element in list __x referenced by __i and inserts it into the current list before __position.
References std::move(), and std::list< _Tp, _Alloc >::splice().
π swap()
template<typename _Tp , typename _Alloc = std::allocator<_Tp>> void
std::list< _Tp, _Alloc >::swap (list< _Tp, _Alloc > & __x) [inline],
[noexcept]
Swaps data with another list. Trade offer: you get my elements, I get yours π€.
__xβ a list of the same element and allocator types.
This exchanges the elements between two lists in constant time. Note that the global std::swap() function is specialized such that std::swap(l1,l2) will feed to this function β so the generic swap just forwards to this one, cute.
Whether the allocators are swapped depends on the allocator traits. That's the fine print, and it matters π.
πΈ unique() β consecutive duplicate cleanup, slay
template<typename _Tp , typename _Alloc > list< _Tp, _Alloc >::__remove_return_type list::unique ()
Okay so unique() removes 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. No cap, that pointer admin is on you.
References: std::list< _Tp, _Alloc >::begin(), std::begin(), std::end(), std::list< _Tp, _Alloc >::size(), and std::list< _Tp, _Alloc >::splice().
π¦ unique(_BinaryPredicate __binary_pred) β predicate-powered duplicate cleanup
template<typename _Tp , typename _Alloc > template<typename _BinaryPredicate > list< _Tp, _Alloc >::__remove_return_type list::unique (_BinaryPredicate __binary_pred)
This overload removes consecutive elements satisfying a predicate. β¨
Template Parameters
_BinaryPredicateβ 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: std::list< _Tp, _Alloc >::begin(), std::begin(), std::end(), std::list< _Tp, _Alloc >::size(), and std::list< _Tp, _Alloc >::splice().
π Author
Generated automatically by Doxygen for libstdc++ from the source code. π Yes bestie, the page says it, not me.
Okay, thatβs the whole page, and the footer deets are: source/version libstdc++, page std::list< _Tp, _Alloc >(3cxx), and the date isnβt printed on that footer line β so Iβm not inventing one, periodt. ππ
π¦ where this page comes from
- ubuntu noble: libstdc++-14-doc 14-20240412-0ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms