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 an initializer_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. the noexcept is part of the package.
  • list (size_type __n, const allocator_type &__a=allocator_type()) β€” creates a list with default constructed elements. __n elements, 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 an initializer_list to a list. brace-list assignment, iconic.
  • void assign (size_type __n, const value_type &__val) β€” assigns a given value to a list. __n copies 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 the c, yes.
  • const_iterator cend () const noexcept β€” signature only. const end with the c, 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 an initializer_list into list before specified const_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. __n copies 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 the noexcept spelling 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. __x is 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, the N in _M_get_Node_allocator is 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_distance overload, 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 to allocator<_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 β€” A const_iterator into the list.
  • __l β€” An initializer_list of value_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 β€” A const_iterator into 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 β€” A const_iterator into 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 β€” A const_iterator into 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 β€” A const_iterator into 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 β€” 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().

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 in x.
  • __last β€” const_iterator referencing the end of the range in x.

Removes the elements in the range [__first,__last) and inserts them before __position in constant time.

⚠️ Undefined if __position is 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 in x.
  • __last β€” const_iterator referencing the end of the range in x.

Removes the elements in the range [__first,__last) and inserts them before __position in constant time.

⚠️ Again: undefined if __position is 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