STD::DEQUE(3)

🫢 std::deque< _Tp, _Alloc > 🫢

Library Functions Manual Β· section 3 πŸ’–

okay bestie. sit down. hydrate. because we are about to talk about the container. this is std::deque< _Tp, _Alloc >, and it is genuinely that girl. πŸŽ€


✨ NAME ✨

std::deque< _Tp, _Alloc > β€” a standard container using fixed-size memory allocation and constant-time manipulation of elements at either end. πŸ’…

yes. either end. both. at once. iconic behaviour honestly. πŸ¦‹


🌸 SYNOPSIS 🌸

#include <deque>

Inherits std::_Deque_base< _Tp, _Alloc >.

bestie note: it's a base class situation, not a "has-a". the deque is a _Deque_base. we love a nepo baby with actual talent. πŸ‘‘

πŸ‘‘ Public Types πŸ‘‘

  • typedef _Alloc allocator_type
  • typedef _Base::const_iterator const_iterator
  • typedef _Alloc_traits::const_pointer const_pointer
  • typedef _Alloc_traits::const_reference const_reference
  • typedef std::reverse_iterator< const_iterator > const_reverse_iterator
  • typedef ptrdiff_t difference_type
  • typedef _Base::iterator iterator
  • typedef _Alloc_traits::pointer pointer
  • typedef _Alloc_traits::reference reference
  • typedef std::reverse_iterator< iterator > reverse_iterator
  • typedef size_t size_type
  • typedef _Tp value_type

look at that little family. 🫢 every one of them is spelled exactly like that, don't you dare "clean them up".


πŸ’… Public Member Functions πŸ’…

  • deque ()=default β€” Creates a deque with no elements. empty. blank slate. main character pre-glow-up era. ✨
  • template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>> deque (_InputIterator __first, _InputIterator __last, const allocator_type &__a=allocator_type()) β€” Builds a deque from a range. πŸ’–
  • deque (const allocator_type &__a) β€” Creates a deque with no elements.
  • deque (const deque &__x) β€” Deque copy constructor. twin energy. πŸ‘―
  • deque (const deque &__x, const __type_identity_t< allocator_type > &__a) β€” Copy constructor with alternative allocator.
  • deque (deque &&)=default β€” Deque move constructor. it's giving "you take the couch, i'm out". πŸ’¨
  • deque (deque &&__x, const __type_identity_t< allocator_type > &__a) β€” Move constructor with alternative allocator.
  • deque (initializer_list< value_type > __l, const allocator_type &__a=allocator_type()) β€” Builds a deque from an initializer list. πŸŽ€
  • deque (size_type __n, const allocator_type &__a=allocator_type()) β€” Creates a deque with default constructed elements.
  • deque (size_type __n, const value_type &__value, const allocator_type &__a=allocator_type()) β€” Creates a deque with copies of an exemplar element.
  • ~deque () β€” the goodbye. 😭
  • template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>> void assign (_InputIterator __first, _InputIterator __last) β€” Assigns a range to a deque.
  • void assign (initializer_list< value_type > __l) β€” Assigns an initializer list to a deque.
  • void assign (size_type __n, const value_type &__val) β€” Assigns a given value to a deque.
  • reference at (size_type __n) β€” Provides access to the data contained in the deque.
  • const_reference at (size_type __n) const β€” Provides access to the data contained in the deque.
  • const_reference back () const noexcept
  • reference back () noexcept
  • const_iterator begin () const noexcept
  • iterator begin () noexcept
  • const_iterator cbegin () const noexcept
  • const_iterator cend () const noexcept
  • void clear () noexcept
  • const_reverse_iterator crbegin () const noexcept
  • const_reverse_iterator crend () const noexcept
  • template<typename... _Args> iterator emplace (const_iterator __position, _Args &&... __args) β€” Inserts an object in deque before specified iterator.
  • template<typename... _Args> reference emplace_back (_Args &&... __args)
  • template<typename... _Args> reference emplace_front (_Args &&... __args)
  • bool empty () const noexcept
  • const_iterator end () const noexcept
  • iterator end () noexcept
  • iterator erase (const_iterator __first, const_iterator __last) β€” Remove a range of elements. βœ‚οΈ
  • iterator erase (const_iterator __position) β€” Remove element at given position.
  • const_reference front () const noexcept
  • reference front () noexcept
  • allocator_type get_allocator () const noexcept β€” Get a copy of the memory allocation object.
  • iterator insert (const_iterator __p, initializer_list< value_type > __l) β€” Inserts an initializer list into the deque.
  • template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>> iterator insert (const_iterator __position, _InputIterator __first, _InputIterator __last) β€” Inserts a range into the deque.
  • iterator insert (const_iterator __position, const value_type &__x) β€” Inserts given value into deque before specified iterator.
  • iterator insert (const_iterator __position, size_type __n, const value_type &__x) β€” Inserts a number of copies of given data into the deque.
  • iterator insert (const_iterator __position, value_type &&__x) β€” Inserts given rvalue into deque before specified iterator.
  • size_type max_size () const noexcept
  • deque & operator= (const deque &__x) β€” Deque assignment operator.
  • deque & operator= (deque &&__x) noexcept(_Alloc_traits::_S_always_equal()) β€” Deque move assignment operator. note the noexcept(_Alloc_traits::_S_always_equal()) right there, she's conditional and she's proud of it. πŸ’…
  • deque & operator= (initializer_list< value_type > __l) β€” Assigns an initializer list to a deque.
  • const_reference operator[] (size_type __n) const noexcept β€” Subscript access to the data contained in the deque.
  • reference operator[] (size_type __n) noexcept β€” Subscript access to the data contained in the deque.
  • void pop_back () noexcept β€” Removes last element.
  • void pop_front () noexcept β€” Removes first element.
  • void push_back (const value_type &__x) β€” Add data to the end of the deque.
  • void push_back (value_type &&__x)
  • void push_front (const value_type &__x) β€” Add data to the front of the deque.
  • void push_front (value_type &&__x)
  • const_reverse_iterator rbegin () const noexcept
  • reverse_iterator rbegin () noexcept
  • const_reverse_iterator rend () const noexcept
  • reverse_iterator rend () noexcept
  • void resize (size_type __new_size) β€” Resizes the deque to the specified number of elements.
  • void resize (size_type __new_size, const value_type &__x) β€” Resizes the deque to the specified number of elements.
  • void shrink_to_fit () noexcept
  • size_type size () const noexcept
  • void swap (deque &__x) noexcept β€” Swaps data with another deque. trading places, but make it legal. πŸ”„

πŸ”’ Protected Types πŸ”’

  • enum { _S_initial_map_size }
  • typedef __gnu_cxx::__alloc_traits< _Map_alloc_type > _Map_alloc_traits
  • typedef _Alloc_traits::template rebind< _Ptr >::other _Map_alloc_type
  • typedef _Alloc_traits::pointer _Ptr
  • typedef _Alloc_traits::const_pointer _Ptr_const
these are the protected ones bestie. not for public consumption. we're just peeking respectfully. πŸ™ˆ

🧚 Protected Member Functions 🧚

  • template<typename _ForwardIterator> void _M_assign_aux (_ForwardIterator __first, _ForwardIterator __last, std::forward_iterator_tag)
  • template<typename _InputIterator> void _M_assign_aux (_InputIterator __first, _InputIterator __last, std::input_iterator_tag)
  • void _M_deallocate_map (_Map_pointer __p, size_t __n) noexcept
  • void _M_default_append (size_type __n)
  • void _M_default_initialize ()
  • template<typename _Alloc1> void _M_destroy_data (iterator __first, iterator __last, const _Alloc1 &)
  • void _M_destroy_data (iterator __first, iterator __last, const std::allocator< _Tp > &)
  • void _M_destroy_data_aux (iterator __first, iterator __last)
  • template<typename... _Args> iterator _M_emplace_aux (iterator __pos, _Args &&... __args)
  • iterator _M_erase (iterator __first, iterator __last)
  • iterator _M_erase (iterator __pos)
  • void _M_erase_at_begin (iterator __pos)
  • void _M_erase_at_end (iterator __pos)
  • void _M_fill_assign (size_type __n, const value_type &__val)
  • void _M_fill_initialize (const value_type &__value) β€” Fills the deque with copies of value.
  • void _M_fill_insert (iterator __pos, size_type __n, const value_type &__x)
  • _Map_alloc_type _M_get_map_allocator () const noexcept
  • template<typename _ForwardIterator> void _M_insert_aux (iterator __pos, _ForwardIterator __first, _ForwardIterator __last, size_type __n)
  • iterator _M_insert_aux (iterator __pos, const value_type &__x)
  • void _M_insert_aux (iterator __pos, size_type __n, const value_type &__x)
  • void _M_move_assign1 (deque &&__x, false_type)
  • void _M_move_assign1 (deque &&__x, true_type) noexcept
  • void _M_move_assign2 (deque &&__x, false_type)
  • void _M_move_assign2 (deque &&__x, true_type)
  • template<typename _InputIterator, typename _Sentinel> void _M_range_append (_InputIterator __first, _Sentinel __last, size_type __n)
  • void _M_range_check (size_type __n) const β€” Safety check used only from at().
  • template<typename _ForwardIterator> void _M_range_insert_aux (iterator __pos, _ForwardIterator __first, _ForwardIterator __last, std::forward_iterator_tag)
  • template<typename _InputIterator> void _M_range_insert_aux (iterator __pos, _InputIterator __first, _InputIterator __last, std::input_iterator_tag)
  • template<typename _InputIterator, typename _Sentinel> void _M_range_prepend (_InputIterator __first, _Sentinel __last, size_type __n)
  • template<typename... _Args> void _M_replace_map (_Args &&... __args)
  • bool _M_shrink_to_fit ()

and then the little sub-clique inside the protected section, same list, just indented:

  • template<typename _InputIterator> void _M_range_initialize (_InputIterator __first, _InputIterator __last, std::input_iterator_tag) β€” Fills the deque with whatever is in [first,last).
  • template<typename _ForwardIterator> void _M_range_initialize (_ForwardIterator __first, _ForwardIterator __last, std::forward_iterator_tag) β€” Fills the deque with whatever is in [first,last).
  • template<typename... _Args> void _M_push_back_aux (_Args &&... __args) β€” Helper functions for push_* and pop_*.
  • template<typename... _Args> void _M_push_front_aux (_Args &&... __args) β€” Helper functions for push_* and pop_*.
  • void _M_pop_back_aux () β€” Helper functions for push_* and pop_*.
  • void _M_pop_front_aux () β€” Helper functions for push_* and pop_*.
  • iterator _M_reserve_elements_at_front (size_type __n) β€” Memory-handling helpers for the previous internal insert functions.
  • iterator _M_reserve_elements_at_back (size_type __n) β€” Memory-handling helpers for the previous internal insert functions.
  • void _M_new_elements_at_front (size_type __new_elements) β€” Memory-handling helpers for the previous internal insert functions.
  • void _M_new_elements_at_back (size_type __new_elements) β€” Memory-handling helpers for the previous internal insert functions.
  • void _M_reserve_map_at_back (size_type __nodes_to_add=1) β€” Memory-handling helpers for the major map. note the default, __nodes_to_add=1. she comes with a default. πŸŽ€
  • void _M_reserve_map_at_front (size_type __nodes_to_add=1) β€” Memory-handling helpers for the major map.
  • void _M_reallocate_map (size_type __nodes_to_add, bool __add_at_front) β€” Memory-handling helpers for the major map.

⭐ Static Protected Member Functions ⭐

  • static size_t _S_check_init_len (size_t __n, const allocator_type &__a)
  • static size_type _S_max_size (const _Tp_alloc_type &__a) noexcept

okay that's the whole types-and-functions lineup for part 1, and we are NOT done yet bestie β€” the rest is coming. stay hydrated, stay seated, do not close the tab. πŸ’œ

🌸 DETAILED DESCRIPTION 🌸

okay bestie, buckle up πŸ’– this is the part where we get into how std::deque actually lives its life, and honestly? it's giving genius.

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
    class std::deque< _Tp, _Alloc >

"A standard container using fixed-size memory allocation and constant-time manipulation of elements at either end." β€” constant-time at either end, yes ma'am, that's the whole flex πŸ‘‘

πŸ’… 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. slay ✨

ok so quick lore drop πŸ«– in previous HP/SGI versions of deque, there was an extra template parameter so users could control the node size. This extension turned out to violate the C++ standard (it can be detected using template template parameters), and it was removed. rip to that extension, you will not be missed πŸ’€

🧚 how the memory actually works (iykyk)

Here's how a deque<Tp> manages memory. Each deque has 4 members:

  • Tp** _M_map
  • size_t _M_map_size
  • iterator _M_start, _M_finish

map_size is at least 8. map is an array of map_size pointers-to-nodes. (The name map has nothing to do with the std::map class, and nodes should not be confused with std::list's usage of node.) <-- important, do not get confused bestie, they are NOT the same thing πŸ™ˆ

A node has no specific type name as such, but it is referred to as node in this file. It is a simple array-of-Tp. If Tp is very large, there will be one Tp element per node (i.e., an array of one). For non-huge Tp's, node size is inversely related to Tp size: the larger the Tp, the fewer Tp's will fit in a node. The goal here is to keep the total size of a node relatively small and constant over different Tp's, to improve allocator efficiency. πŸŽ€

Not every pointer in the map array will point to a node. If the initial number of elements in the deque is small, the /middle/ map pointers will be valid, and the ones at the edges will be unused. This same situation will arise as the map grows: available map pointers, if any, will be on the ends. As new nodes are created, only a subset of the map's pointers need to be copied outward. efficient queen πŸ’…

🌈 Class invariants

  • For any nonsingular iterator i:
    • i.node points to a member of the map array. (Yes, you read that correctly: i.node does not actually point to a node.) The member of the map array is what actually points to the node.
    • i.first == *(i.node) (This points to the node (first Tp element).)
    • i.last == i.first + node_size
    • i.cur is a pointer in the range [i.first, i.last). NOTE: the implication of this is that i.cur is always a dereferenceable pointer, even if i is a past-the-end iterator.
  • Start and Finish are always nonsingular iterators. NOTE: this means that an empty deque must have one node, a deque with <N elements (where N is the node buffer size) must have one node, a deque with N through (2N-1) elements must have two nodes, etc.
  • For every node other than start.node and finish.node, every element in the node is an initialized object. If start.node == finish.node, then [start.cur, finish.cur) are initialized objects, and the elements outside that range are uninitialized storage. Otherwise, [start.cur, start.last) and [finish.first, finish.cur) are initialized objects, and [start.first, start.cur) and [finish.cur, finish.last) are uninitialized storage.
  • [map, map + map_size) is a valid, non-empty range.
  • [start.node, finish.node] is a valid range contained within [map, map + map_size).
  • A pointer in the range [map, map + map_size) points to an allocated node if and only if the pointer is in the range [start.node, finish.node].

Here's the magic: nothing in deque is aware of the discontiguous storage! 🀯 like she literally does not know and does not care

The memory setup and layout occurs in the parent, _Base, and the iterator class is entirely responsible for leaping from one node to the next. All the implementation routines for deque itself work only through the start and finish iterators. This keeps the routines simple and sane, and we can use other standard algorithms as well. 🫢 main character iterator energy fr fr


πŸ’– CONSTRUCTOR & DESTRUCTOR DOCUMENTATION πŸ’–

πŸŽ€ deque () β€” [default]

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
    std::deque< _Tp, _Alloc >::deque ()

Creates a deque with no elements. ✨ literally the empty girlie, no thoughts, just vibes

Referenced by insert(), and operator=().

πŸŽ€ deque (const allocator_type & __a) β€” [inline], [explicit]

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
    std::deque< _Tp, _Alloc >::deque (const allocator_type & __a)

Creates a deque with no elements.

Parameters

  • __a β€” An allocator object.

πŸŽ€ deque (size_type __n, const allocator_type & __a = allocator_type()) β€” [inline], [explicit]

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
    std::deque< _Tp, _Alloc >::deque (size_type __n, const allocator_type & __a = allocator_type())

Creates a deque with default constructed elements.

Parameters

  • __n β€” The number of elements to initially create.
  • __a β€” An allocator.

This constructor fills the deque with n default constructed elements.

πŸŽ€ deque (size_type __n, const value_type & __value, const allocator_type & __a = allocator_type()) β€” [inline]

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
    std::deque< _Tp, _Alloc >::deque (size_type __n, const value_type & __value, const allocator_type & __a = allocator_type())

Creates a deque with copies of an exemplar element.

Parameters

  • __n β€” The number of elements to initially create.
  • __value β€” An element to copy.
  • __a β€” An allocator.

This constructor fills the deque with __n copies of __value. copy-paste but make it fashion πŸ’…

πŸŽ€ deque (const deque< _Tp, _Alloc > & __x) β€” [inline]

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
    std::deque< _Tp, _Alloc >::deque (const deque< _Tp, _Alloc > & __x)

Deque copy constructor. 🫢

Parameters

  • __x β€” A deque of identical element and allocator types.

The newly-created deque uses a copy of the allocator object used by __x (unless the allocator traits dictate a different object).

πŸŽ€ deque (deque< _Tp, _Alloc > && ) β€” [default]

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
    std::deque< _Tp, _Alloc >::deque (deque< _Tp, _Alloc > && )

Deque move constructor. The newly-created deque contains the exact contents of the moved instance. The contents of the moved instance are a valid, but unspecified deque.

heads up bestie: after the move, the moved-from deque is "valid, but unspecified" β€” that means it exists, it's legal, but do NOT count on what's inside it. valid but feral πŸ™ˆ

πŸŽ€ deque (const deque< _Tp, _Alloc > & __x, const __type_identity_t< allocator_type > & __a) β€” [inline]

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
    std::deque< _Tp, _Alloc >::deque (const deque< _Tp, _Alloc > & __x, const __type_identity_t< allocator_type > & __a)

Copy constructor with alternative allocator.

πŸŽ€ deque (deque< _Tp, _Alloc > && __x, const __type_identity_t< allocator_type > & __a) β€” [inline]

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
    std::deque< _Tp, _Alloc >::deque (deque< _Tp, _Alloc > && __x, const __type_identity_t< allocator_type > & __a)

Move constructor with alternative allocator.

πŸŽ€ deque (initializer_list< value_type > __l, const allocator_type & __a = allocator_type()) β€” [inline]

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
    std::deque< _Tp, _Alloc >::deque (initializer_list< value_type > __l, const allocator_type & __a = allocator_type())

Builds a deque from an initializer list. πŸŽ€

Parameters

  • __l β€” An initializer_list.
  • __a β€” An allocator object.

Create a deque consisting of copies of the elements in the initializer_list __l.

This will call the element type's copy constructor N times (where N is __l.size()) and do no memory reallocation.

πŸŽ€ deque (_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::deque< _Tp, _Alloc >::deque (_InputIterator __first, _InputIterator __last, const allocator_type & __a = allocator_type())

Builds a deque from a range. πŸ¦‹

Parameters

  • __first β€” An input iterator.
  • __last β€” An input iterator.
  • __a β€” An allocator object.

Create a deque consisting of copies of the elements from [__first, __last).

If the iterators are forward, bidirectional, or random-access, then this will call the elements' copy constructor N times (where N is distance(__first,__last)) and do no memory reallocation. But if only input iterators are used, then this will do at most 2N calls to the copy constructor, and logN memory reallocations. so like... know your iterator category bestie, it changes the whole vibe check πŸ“Š

πŸŽ€ ~deque () β€” [inline]

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
    std::deque< _Tp, _Alloc >::~deque ()

The 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. ⚠️

no cap, this one matters: if your deque holds raw pointers, destroying the deque does NOT free what they point to. that's on you, bestie. she cleans up her own mess only πŸ’€

✨ MEMBER FUNCTION DOCUMENTATION ✨

πŸ¦‹ _M_fill_initialize (const value_type & __value) β€” [protected]

template<typename _Tp, typename _Alloc>
    void deque::_M_fill_initialize (const value_type & __value)

Fills the deque with copies of value.

Parameters

  • __value β€” Initial value.

Precondition

_M_start and _M_finish have already been initialized, but none of the deque's elements have yet been constructed.

This function is called only when the user provides an explicit size (with or without an explicit exemplar value).

References std::_Destroy().

Referenced by std::deque< _Tp, polymorphic_allocator< _Tp > >::deque().

πŸ¦‹ _M_new_elements_at_back (size_type __new_elements) β€” [protected]

template<typename _Tp, typename _Alloc>
    void deque::_M_new_elements_at_back (size_type __new_elements)

Memory-handling helpers for the previous internal insert functions.

References _M_reserve_map_at_back(), max_size(), and std::size().

Referenced by std::deque< _Tp, polymorphic_allocator< _Tp > >::_M_reserve_elements_at_back().

πŸ¦‹ _M_new_elements_at_front (size_type __new_elements) β€” [protected]

template<typename _Tp, typename _Alloc>
    void deque::_M_new_elements_at_front (size_type __new_elements)

Memory-handling helpers for the previous internal insert functions.

References _M_reserve_map_at_front(), max_size(), and std::size().

Referenced by std::deque< _Tp, polymorphic_allocator< _Tp > >::_M_reserve_elements_at_front().

πŸ¦‹ _M_pop_back_aux () β€” [protected]

template<typename _Tp, typename _Alloc>
    void deque::_M_pop_back_aux ()

Helper functions for push_* and pop_*.

Referenced by std::deque< _Tp, polymorphic_allocator< _Tp > >::pop_back().

πŸ¦‹ _M_pop_front_aux () β€” [protected]

template<typename _Tp, typename _Alloc>
    void deque::_M_pop_front_aux ()

Helper functions for push_* and pop_*.

Referenced by std::deque< _Tp, polymorphic_allocator< _Tp > >::pop_front().

πŸ¦‹ _M_push_back_aux (_Args &&... __args) β€” [protected]

template<typename _Tp, typename _Alloc>
    template<typename... _Args>
    void deque::_M_push_back_aux (_Args &&... __args)

Helper functions for push_* and pop_*.

References _M_reserve_map_at_back(), std::forward(), max_size(), and std::size().

Referenced by std::deque< _Tp, polymorphic_allocator< _Tp > >::push_back().

πŸ¦‹ _M_push_front_aux (_Args &&... __args) β€” [protected]

template<typename _Tp, typename _Alloc>
    template<typename... _Args>
    void deque::_M_push_front_aux (_Args &&... __args)

Helper functions for push_* and pop_*.

References _M_reserve_map_at_front(), std::forward(), max_size(), and std::size().

Referenced by std::deque< _Tp, polymorphic_allocator< _Tp > >::push_front().

πŸ¦‹ _M_range_check (size_type __n) const β€” [inline], [protected]

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
    void std::deque< _Tp, _Alloc >::_M_range_check (size_type __n) const

Safety check used only from at(). πŸ›‘οΈ

Referenced by std::deque< _Tp, polymorphic_allocator< _Tp > >::at(), and std::deque< _Tp, polymorphic_allocator< _Tp > >::at().

🫢 deque::_M_range_initialize β€” the forward-iterator glow-up

template<typename _Tp, typename _Alloc> template<typename _ForwardIterator>
    void deque::_M_range_initialize (_ForwardIterator __first,
    _ForwardIterator __last, std::forward_iterator_tag ) [protected]

Okay so bestie, this one fills the deque with whatever is in [first,last). That's the whole vibe. ✨

Parameters

  • __first β€” an input iterator. πŸŽ€
  • __last β€” an input iterator. πŸŽ€

Now here's the tea: if the iterators are actually forward iterators (or better), then the memory layout can be done all at once, in one big slay. Else we move forward using push_back on each value from the iterator, one by one, like texting your bestie individually instead of making a group chat. 😭

  • References β€” std::_Destroy(), std::advance(), and std::distance().

πŸ¦‹ deque::_M_range_initialize β€” the input-iterator remix

template<typename _Tp, typename _Alloc> template<typename _InputIterator>
    void deque::_M_range_initialize (_InputIterator __first, _InputIterator
    __last, std::input_iterator_tag ) [protected]

Same energy, different tag: this one also fills the deque with whatever is in [first,last).

Parameters

  • __first β€” an input iterator. 🌸
  • __last β€” an input iterator. 🌸

And again: if the iterators are actually forward iterators (or better), then the memory layout can be done all at once. Else we move forward using push_back on each value from the iterator. Periodt. πŸ’…

  • References β€” clear(), and push_back().
  • Referenced by β€” std::deque< _Tp, polymorphic_allocator< _Tp > >::deque(), and std::deque< _Tp, polymorphic_allocator< _Tp > >::deque(). (Yes bestie, it's listed twice, that's literally what the page says, I don't make the rules 🫠)

🌈 deque::_M_reallocate_map

template<typename _Tp, typename _Alloc> void deque::_M_reallocate_map
    (size_type __nodes_to_add, bool __add_at_front) [protected]

Memory-handling helpers for the major map. πŸ‘‘

The way this one works: it makes sure the _M_map has space for new nodes. It does NOT actually add the nodes β€” it's just making room, like clearing a shelf before you buy more Squishmallows. 🧸

⚠️ It can invalidate _M_map pointers. (And consequently, deque iterators.) So if you were holding onto an iterator, uh, that's a you problem now. πŸ’€
  • References β€” std::max(), and max_size().
  • Referenced by β€” std::deque< _Tp, polymorphic_allocator< _Tp > >::_M_reserve_map_at_back(), and std::deque< _Tp, polymorphic_allocator< _Tp > >::_M_reserve_map_at_front().

πŸŽ€ deque::_M_reserve_elements_at_back

template<typename _Tp, typename _Alloc = std::allocator<_Tp>> iterator
    std::deque< _Tp, _Alloc >::_M_reserve_elements_at_back (size_type __n)
    [inline],  [protected]

Memory-handling helpers for the previous internal insert functions. That's it, that's the whole description, no cap. It's giving "internal, don't worry about it" energy. πŸ™ˆ


πŸŽ€ deque::_M_reserve_elements_at_front

template<typename _Tp, typename _Alloc = std::allocator<_Tp>> iterator
    std::deque< _Tp, _Alloc >::_M_reserve_elements_at_front (size_type __n)
    [inline],  [protected]

Memory-handling helpers for the previous internal insert functions. Same sentence, same energy, just the front-flavored version. ✨


πŸ’œ deque::_M_reserve_map_at_back

template<typename _Tp, typename _Alloc = std::allocator<_Tp>> void
    std::deque< _Tp, _Alloc >::_M_reserve_map_at_back (size_type
    __nodes_to_add = 1) [inline],  [protected]

Memory-handling helpers for the major map. Makes sure the _M_map has space for new nodes. Does not actually add the nodes. Can invalidate _M_map pointers β€” and consequently, deque iterators. πŸ’€

  • Referenced by β€” _M_new_elements_at_back(), and _M_push_back_aux().

πŸ’œ deque::_M_reserve_map_at_front

template<typename _Tp, typename _Alloc = std::allocator<_Tp>> void
    std::deque< _Tp, _Alloc >::_M_reserve_map_at_front (size_type
    __nodes_to_add = 1) [inline],  [protected]

Memory-handling helpers for the major map. Makes sure the _M_map has space for new nodes. Does not actually add the nodes. Can invalidate _M_map pointers β€” and consequently, deque iterators. 🫠

  • Referenced by β€” _M_new_elements_at_front(), and _M_push_front_aux().

πŸ“ deque::assign β€” the iterator-range edition

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
    template<typename _InputIterator, typename =
    std::_RequireInputIter<_InputIterator>> void std::deque< _Tp, _Alloc
    >::assign (_InputIterator __first, _InputIterator __last) [inline]

Assigns a range to a deque. πŸ’–

Parameters

  • __first β€” an input iterator. 🌸
  • __last β€” an input iterator. 🌸

This function fills a deque with copies of the elements in the range [__first,__last).

🚨 Heads up: the assignment completely changes the deque, and the resulting deque's size is the same as the number of elements assigned. So don't come crying that your old stuff vanished β€” it was never gonna survive this. 😭

πŸ“ deque::assign β€” the initializer-list edition

template<typename _Tp, typename _Alloc = std::allocator<_Tp>> void
    std::deque< _Tp, _Alloc >::assign (initializer_list< value_type > __l)
    [inline]

Assigns an initializer list to a deque. ✨

Parameters

  • __l β€” an initializer_list. πŸŽ€

This function fills a deque with copies of the elements in the initializer_list __l.

🚨 Same warning, bestie: the assignment completely changes the deque, and the resulting deque's size is the same as the number of elements assigned. It's giving "out with the old, in with the new." πŸ’…

πŸ“ deque::assign β€” the n-copies-of-a-value edition

template<typename _Tp, typename _Alloc = std::allocator<_Tp>> void
    std::deque< _Tp, _Alloc >::assign (size_type __n, const value_type &
    __val) [inline]

Assigns a given value to a deque. 🌸

Parameters

  • __n β€” number of elements to be assigned.
  • __val β€” value to be assigned.

This function fills a deque with n copies of the given value. And you already know the note: the assignment completely changes the deque and the resulting deque's size is the same as the number of elements assigned. 😌


🧚 deque::at β€” read/write version

template<typename _Tp, typename _Alloc = std::allocator<_Tp>> reference
    std::deque< _Tp, _Alloc >::at (size_type __n) [inline]

Provides access to the data contained in the deque. πŸ‘‘

Parameters

  • __n β€” the index of the element for which data should be accessed.

Returns

  • Read/write reference to data. πŸ”₯

Exceptions

  • std::out_of_range β€” if __n is an invalid index.

This function provides for safer data access. The parameter is first checked that it is in the range of the deque. The function throws out_of_range if the check fails. So like, this is the version with a seatbelt. πŸŽ€


🧚 deque::at β€” the const edition

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
    const_reference std::deque< _Tp, _Alloc >::at (size_type __n) const
    [inline]

Provides access to the data contained in the deque. 🌸

Parameters

  • __n β€” the index of the element for which data should be accessed.

Returns

  • Read-only (constant) reference to data. ✨

Exceptions

  • std::out_of_range β€” if __n is an invalid index.

Again: safer data access. The parameter is first checked that it is in the range of the deque, and the function throws out_of_range if the check fails. No peeking past the edge, bestie. πŸ’…


πŸ‘‘ deque::back β€” const edition

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
    const_reference std::deque< _Tp, _Alloc >::back () const [inline],
    [nodiscard],  [noexcept]

Returns a read-only (constant) reference to the data at the last element of the deque. The literal last one. The final girl. πŸ’–


πŸ‘‘ deque::back β€” read/write edition

template<typename _Tp, typename _Alloc = std::allocator<_Tp>> reference
    std::deque< _Tp, _Alloc >::back () [inline],  [nodiscard],  [noexcept]

Returns a read/write reference to the data at the last element of the deque. Same last element, but now you can actually edit it. Main character energy. πŸ”₯


🌸 deque::begin β€” const edition

template<typename _Tp, typename _Alloc = std::allocator<_Tp>> const_iterator
    std::deque< _Tp, _Alloc >::begin () const [inline],  [nodiscard],
    [noexcept]

Returns a read-only (constant) iterator that points to the first element in the deque. Iteration is done in ordinary element order. πŸ¦‹


🌸 deque::begin β€” read/write edition

template<typename _Tp, typename _Alloc = std::allocator<_Tp>> iterator
    std::deque< _Tp, _Alloc >::begin () [inline],  [nodiscard],  [noexcept]

Returns a read/write iterator that points to the first element in the deque. Iteration is done in ordinary element order. ✨

  • Referenced by β€” std::deque< _Tp, polymorphic_allocator< _Tp > >::deque(), std::deque< _Tp, polymorphic_allocator< _Tp > >::deque(), std::deque< _Tp, polymorphic_allocator< _Tp > >::~deque(), std::deque< _Tp, polymorphic_allocator< _Tp > >::clear(), std::deque< _Tp, polymorphic_allocator< _Tp > >::front(), std::deque< _Tp, polymorphic_allocator< _Tp > >::front(), std::deque< _Tp, polymorphic_allocator< _Tp > >::insert(), std::deque< _Tp, polymorphic_allocator< _Tp > >::insert(), std::deque< _Tp, polymorphic_allocator< _Tp > >::insert(), std::operator<=>(), and operator=(). (It's booked and busy fr fr πŸ’…)

πŸŽ€ deque::cbegin

template<typename _Tp, typename _Alloc = std::allocator<_Tp>> const_iterator
    std::deque< _Tp, _Alloc >::cbegin () const [inline],  [noexcept]

Returns a read-only (constant) iterator that points to the first element in the deque. Iteration is done in ordinary element order. 🌈

  • Referenced by β€” std::deque< _Tp, polymorphic_allocator< _Tp > >::insert(), std::deque< _Tp, polymorphic_allocator< _Tp > >::insert(), and std::deque< _Tp, polymorphic_allocator< _Tp > >::insert().

πŸŽ€ deque::cend

template<typename _Tp, typename _Alloc = std::allocator<_Tp>> const_iterator
    std::deque< _Tp, _Alloc >::cend () const [inline],  [noexcept]

Returns a read-only (constant) iterator that points one past the last element in the deque. Iteration is done in ordinary element order. One past the last β€” like the empty seat at the end of the row. 🫢


🧹 deque::clear

template<typename _Tp, typename _Alloc = std::allocator<_Tp>> void
    std::deque< _Tp, _Alloc >::clear () [inline],  [noexcept]

Erases all the elements. Full reset, clean slate, new era. ✨

⚠️ But listen: this function only erases the elements, and if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility. So like, clear() is not your cleanup crew, bestie, it's just the eraser. 😭
  • Referenced by β€” _M_range_initialize().

πŸ¦‹ deque::crbegin

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
    const_reverse_iterator std::deque< _Tp, _Alloc >::crbegin () const
    [inline],  [noexcept]

Returns a read-only (constant) reverse iterator that points to the last element in the deque. Iteration is done in reverse element order. Backwards, but make it fashion. πŸ’…


πŸ¦‹ deque::crend

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
    const_reverse_iterator std::deque< _Tp, _Alloc >::crend () const
    [inline],  [noexcept]

Returns a read-only (constant) reverse iterator that points to one before the first element in the deque. Iteration is done in reverse element order. 🌸


πŸ’– deque::emplace

template<typename _Tp, typename _Alloc> template<typename... _Args> deque<
    _Tp, _Alloc >::iterator deque::emplace (const_iterator __position, _Args
    &&... __args)

Inserts an object in deque before specified iterator. πŸ‘‘

Parameters

  • __position β€” a const_iterator into the deque. πŸŽ€
  • __args β€” arguments.

Returns

  • An iterator that points to the inserted data. ✨

This function will insert an object of type T constructed with T(std::forward<Args>(args)...) before the specified location. It builds the thing right there in place, no copy, no drama. πŸ”₯

  • References β€” std::forward().
  • Referenced by β€” std::deque< _Tp, polymorphic_allocator< _Tp > >::insert().

🫧 deque::empty

template<typename _Tp, typename _Alloc = std::allocator<_Tp>> bool
    std::deque< _Tp, _Alloc >::empty () const [inline],  [nodiscard],
    [noexcept]

Returns true if the deque is empty. (Thus begin() would equal end().) 🌈


⭐ deque::end β€” const edition

template<typename _Tp, typename _Alloc = std::allocator<_Tp>> const_iterator
    std::deque< _Tp, _Alloc >::end () const [inline],  [nodiscard],
    [noexcept]

Returns a read-only (constant) iterator that points one past the last element in the deque. Iteration is done in ordinary element order. πŸ’œ


⭐ deque::end β€” read/write edition

template<typename _Tp, typename _Alloc = std::allocator<_Tp>> iterator
    std::deque< _Tp, _Alloc >::end () [inline],  [nodiscard],  [noexcept]

Returns a read/write iterator that points one past the last element in the deque. Iteration is done in ordinary element order. That's the finish line, not the last element β€” one past it. Don't dereference it, bestie, I'm begging. 😭🫢

  • Referenced by std::deque< _Tp, polymorphic_allocator< _Tp > >::deque(), std::deque< _Tp, polymorphic_allocator< _Tp > >::deque(), std::deque< _Tp, polymorphic_allocator< _Tp > >::~deque(), std::deque< _Tp, polymorphic_allocator< _Tp > >::back(), std::deque< _Tp, polymorphic_allocator< _Tp > >::back(), std::operator<=>(), and operator=().

πŸ—‘οΈ erase β€” the range version

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
iterator
std::deque< _Tp, _Alloc >::erase (const_iterator __first, const_iterator __last) [inline]

Remove a range of elements. Yes bestie, plural, a whole range, we're not being shy about it πŸ’…

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()).

So like, this function will erase the elements in the range [__first,__last) and shorten the deque accordingly. Iconic. ✨

⚠️ Caution, babes: 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 on you, not on the deque. No cap. πŸ™ˆ

πŸ—‘οΈ erase β€” the single-element version

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
iterator
std::deque< _Tp, _Alloc >::erase (const_iterator __position) [inline]

Remove element at given position. One at a time, we love a precise queen. πŸŽ€

Parameters

  • __position β€” iterator pointing to the 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 deque by one. πŸ“‰

⚠️ Same warning, same energy: 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. 🫢

πŸ₯‡ front β€” const flavour

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
const_reference
std::deque< _Tp, _Alloc >::front () const [inline], [nodiscard], [noexcept]

Returns a read-only (constant) reference to the data at the first element of the deque. Look but don't touch, respectfully. πŸ‘€


πŸ₯‡ front β€” the read/write flavour

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
reference
std::deque< _Tp, _Alloc >::front () [inline], [nodiscard], [noexcept]

Returns a read/write reference to the data at the first element of the deque. Now this one you can edit. Main character energy at index zero. πŸ‘‘


🧾 get_allocator

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
allocator_type
std::deque< _Tp, _Alloc >::get_allocator () const [inline], [nodiscard], [noexcept]

Get a copy of the memory allocation object. Just a little photocopy of the allocator, nbd. πŸ–¨οΈ

Referenced by operator=().


βž• insert β€” initializer_list version

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
iterator
std::deque< _Tp, _Alloc >::insert (const_iterator __p, initializer_list< value_type > __l) [inline]

Inserts an initializer list into the deque. Curly braces girlies, this one's for you. πŸ’–

Parameters

  • __p β€” an iterator into the deque.
  • __l β€” an initializer_list.

Returns

An iterator that points to the inserted data.

This function will insert copies of the data in the initializer_list __l into the deque before the location specified by __p. This is known as list insert. Slay. ✨


βž• insert β€” the range version

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>>
iterator
std::deque< _Tp, _Alloc >::insert (const_iterator __position, _InputIterator __first, _InputIterator __last) [inline]

Inserts a range into the deque. Bulk insertion, we're efficient here. πŸ’…

Parameters

  • __position β€” a const_iterator into the deque.
  • __first β€” an input iterator.
  • __last β€” an input iterator.

Returns

An iterator that points to the inserted data.

This function will insert copies of the data in the range [__first,__last) into the deque before the location specified by __position. This is known as range insert. 🌈


βž• insert β€” insert one value before an iterator

template<typename _Tp, typename _Alloc>
deque< _Tp, _Alloc >::iterator
deque::insert (const_iterator __position, const value_type & __x)

Inserts given value into deque before specified iterator.

Parameters

  • __position β€” a const_iterator into the deque.
  • __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. 🫰

References deque(), insert(), push_back(), and push_front().

Referenced by insert().


βž• insert β€” n copies of a value

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
iterator
std::deque< _Tp, _Alloc >::insert (const_iterator __position, size_type __n, const value_type & __x) [inline]

Inserts a number of copies of given data into the deque. Same value, many times, it's giving clone army. πŸ‘―

Parameters

  • __position β€” a const_iterator into the deque.
  • __n β€” number of elements to be inserted.
  • __x β€” data to be inserted.

Returns

An iterator that points to the inserted data.

This function will insert a specified number of copies of the given data before the location specified by __position. ✨


βž• insert β€” rvalue version

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
iterator
std::deque< _Tp, _Alloc >::insert (const_iterator __position, value_type && __x) [inline]

Inserts given rvalue into deque before specified iterator. Moving that value in, we love a relocation arc. 🚚

Parameters

  • __position β€” a const_iterator into the deque.
  • __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. πŸ”₯


πŸ“ max_size

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
size_type
std::deque< _Tp, _Alloc >::max_size () const [inline], [nodiscard], [noexcept]

Returns the size() of the largest possible deque. Like, theoretically. The ceiling. The absolute limit. 🌌

Referenced by _M_new_elements_at_back(), _M_new_elements_at_front(), _M_push_back_aux(), _M_push_front_aux(), and _M_reallocate_map().


πŸ“‹ operator= β€” copy assignment

template<typename _Tp, typename _Alloc>
deque< _Tp, _Alloc > &
deque::operator= (const deque< _Tp, _Alloc > & __x)

Deque assignment operator.

Parameters

  • __x β€” a deque of identical element and allocator types.

All the elements of x are copied. πŸ“„

The newly-created deque uses a copy of the allocator object used by __x (unless the allocator traits dictate a different object). iykyk. 🧚

References deque(), std::__addressof(), begin(), end(), get_allocator(), size(), and std::size().


πŸ“‹ operator= β€” move assignment

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
deque &
std::deque< _Tp, _Alloc >::operator= (deque< _Tp, _Alloc > && __x) [inline], [noexcept]

Deque move assignment operator. We're relocating, not copying. Efficiency queen. πŸ‘‘

Parameters

  • __x β€” a deque of identical element and allocator types.

The contents of __x are moved into this deque (without copying, if the allocators permit it). __x is a valid, but unspecified deque. 😭 (yes that's a real caveat, don't come for me)


πŸ“‹ operator= β€” initializer_list assignment

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
deque &
std::deque< _Tp, _Alloc >::operator= (initializer_list< value_type > __l) [inline]

Assigns an initializer list to a deque.

Parameters

  • __l β€” an initializer_list.

This function fills a deque with copies of the elements in the initializer_list __l. ✨

Note that the assignment completely changes the deque and that the resulting deque's size() is the same as the number of elements assigned. Total glow-up, full reset. πŸ’…

πŸ”’ operator[] β€” const subscript

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
const_reference
std::deque< _Tp, _Alloc >::operator[] (size_type __n) const [inline], [nodiscard], [noexcept]

Subscript access to the data contained in the deque.

Parameters

  • __n β€” the index of the element for which data should be accessed.

Returns

Read-only (constant) reference to data.

This operator allows for easy, array-style, data access. πŸŽ€

⚠️ Real talk: data access with this operator is unchecked and out_of_range lookups are not defined. (For checked lookups see at().) She does not check IDs at the door, bestie. πŸšͺπŸ’€

πŸ”’ operator[] β€” read/write subscript

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
reference
std::deque< _Tp, _Alloc >::operator[] (size_type __n) [inline], [nodiscard], [noexcept]

Subscript access to the data contained in the deque.

Parameters

  • __n β€” the index of the element for which data should be accessed.

Returns

Read/write reference to data.

This operator allows for easy, array-style, data access. πŸŽ€

⚠️ Same energy: data access with this operator is unchecked and out_of_range lookups are not defined. (For checked lookups see at().) 🫢

πŸ“€ pop_back

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
void
std::deque< _Tp, _Alloc >::pop_back () [inline], [noexcept]

Removes last element. This is a typical stack operation. It shrinks the deque by one. πŸ“‰

Note that no data is returned, and if the last element's data is needed, it should be retrieved before pop_back() is called. Grab it first or it's gone forever, babes. 😭

πŸ“€ pop_front

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
void
std::deque< _Tp, _Alloc >::pop_front () [inline], [noexcept]

Removes first element. This is a typical stack operation. It shrinks the deque by one. πŸ“‰

Note that no data is returned, and if the first element's data is needed, it should be retrieved before pop_front() is called. Save it to a variable first, I'm begging. πŸ™ˆ

πŸ“₯ push_back

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
void
std::deque< _Tp, _Alloc >::push_back (const value_type & __x) [inline]

Add data to the end of the deque.

Parameters

  • __x β€” data to be added.

This is a typical stack operation. The function creates an element at the end of the deque and assigns the given data to it. Due to the nature of a deque this operation can be done in constant time. O(1) queen, we love her. πŸ”₯

Referenced by _M_range_initialize(), and insert().


πŸ“₯ push_front

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
void
std::deque< _Tp, _Alloc >::push_front (const value_type & __x) [inline]

Add data to the front of the deque.

Parameters

  • __x β€” data to be added.

This is a typical stack operation. The function creates an element at the front of the deque and assigns the given data to it. Due to the nature of a deque this operation can be done in constant time. Front insertion that isn't slow?? The way that a deque just does that. πŸ’…

Referenced by insert().


βͺ rbegin β€” const reverse begin

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
const_reverse_iterator
std::deque< _Tp, _Alloc >::rbegin () const [inline], [nodiscard], [noexcept]

Returns a read-only (constant) reverse iterator that points to the last element in the deque. Iteration is done in reverse element order. Backwards, but make it fashion. πŸ¦‹


βͺ rbegin β€” read/write reverse begin

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
reverse_iterator
std::deque< _Tp, _Alloc >::rbegin () [inline], [nodiscard], [noexcept]

Returns a read/write reverse iterator that points to the last element in the deque. Iteration is done in reverse element order. Editable and backwards, she contains multitudes. ✨


βͺ rend β€” const reverse end

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
const_reverse_iterator
std::deque< _Tp, _Alloc >::rend () const [inline], [nodiscard], [noexcept]

Returns a read-only (constant) reverse iterator that points to one before the first element in the deque. Iteration is done in reverse element order. 🌸

okay so continuing our deep dive into std::deque's member functions, bestie πŸ’– we got a few more to cover, and they're all kinda iconic ngl. let's get into it ✨


rend() πŸ”„

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
reverse_iterator std::deque< _Tp, _Alloc >::rend () [inline], [nodiscard], [noexcept]

Returns a read/write reverse iterator that points to one before the first element in the deque. Iteration is done in reverse element order.

it's giving [inline], [nodiscard] (so don't ignore that return value, bestie, that's rude), and [noexcept] (no throwing here, we're chill). slay πŸ’…


resize(size_type __new_size) πŸ“

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
void std::deque< _Tp, _Alloc >::resize (size_type __new_size) [inline]

Parameters:

  • __new_size β€” Number of elements the deque should contain.

This function will resize the deque to the specified number of elements. If the number is smaller than the deque's current size the deque is truncated, otherwise default constructed elements are appended.

so basically if you want it smaller, it gets cut off, and if you want it bigger, it fills in with default-constructed goodies. no cap 🧚


resize(size_type __new_size, const value_type & __x) πŸ“

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
void std::deque< _Tp, _Alloc >::resize (size_type __new_size, const value_type & __x) [inline]

Parameters:

  • __new_size β€” Number of elements the deque should contain.
  • __x β€” Data with which new elements should be populated.

This function will resize the deque to the specified number of elements. If the number is smaller than the deque's current size the deque is truncated, otherwise the deque is extended and new elements are populated with given data.

so you can pass a little value __x and it'll copy that into all the new spots. obsessed πŸ’œ


shrink_to_fit() πŸͺ„

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
void std::deque< _Tp, _Alloc >::shrink_to_fit () [inline], [noexcept]

A non-binding request to reduce memory use.

it's literally just a polite ask to the container, like "hey bestie, can you free up some space?" β€” but it's non-binding, so it might not actually do it. still iconic tho ✨


size() πŸ“Š

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
size_type std::deque< _Tp, _Alloc >::size () const [inline], [nodiscard], [noexcept]

Returns the number of elements in the deque.

Referenced by std::deque< _Tp, polymorphic_allocator< _Tp > >::_M_range_check(), std::operator<=>(), operator=(), std::deque< _Tp, polymorphic_allocator< _Tp > >::resize(), and std::deque< _Tp, polymorphic_allocator< _Tp > >::resize().

like, it's the headcount of your deque. [nodiscard] so you better use that number for something, and [noexcept] so it's safe. periodt πŸ’š


swap(deque< _Tp, _Alloc > & __x) πŸ”„

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
void std::deque< _Tp, _Alloc >::swap (deque< _Tp, _Alloc > & __x) [inline], [noexcept]

Parameters:

  • __x β€” A deque of the same element and allocator types.

This exchanges the elements between two deques in constant time. (Four pointers, so it should be quite fast.) Note that the global std::swap() function is specialized such that std::swap(d1,d2) will feed to this function.

Whether the allocators are swapped depends on the allocator traits.

so it's a quick little trade β€” just swapping pointers, no biggie. four pointers and it's done, fr fr. and if you call std::swap(d1,d2) it'll route right here. iykyk πŸ’™


Author ✍️

Generated automatically by Doxygen for libstdc++ from the source code.


and that's a wrap on this page from libstdc++, specifically std::deque...p, _Alloc >(3) 🌸 no cap, you just read the whole thing. you're literally the main character. slay πŸ’…πŸ’–βœ¨

πŸ“¦ where this page comes from
  • arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
  • fedora 44: libstdc++-docs 16.2.1-2.fc44
  • fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms