STD::DEQUE(3cxx)

πŸ’– NAME πŸ’–

std::deque< _Tp, _Alloc > β€” bestie, welcome to the manual page for std::deque< _Tp, _Alloc >, straight out of the 3cxx manual section (that's the (3cxx) bit, iykyk πŸ’…).

Okay so what is she? A standard container using fixed-size memory allocation and constant-time manipulation of elements at either end. Like a glow-up of a vector where both ends get main character energy. ✨


✨ SYNOPSIS ✨

#include <deque>

Inherits std::_Deque_base< _Tp, _Alloc >. 🫢

πŸŽ€ Public Types πŸŽ€

  • typedef _Alloc allocator_type β€” the allocator's type, slaying under an alias πŸ’«
  • typedef _Base::const_iterator const_iterator β€” iterator but make it can't touch this πŸ™ˆ
  • typedef _Alloc_traits::const_pointer const_pointer β€” a pointer that knows its place (const) πŸŽ€
  • typedef _Alloc_traits::const_reference const_reference β€” a const reference, respectfully ✨
  • typedef std::reverse_iterator< const_iterator > const_reverse_iterator β€” a const iterator that walks backwards, iconic πŸ¦‹
  • typedef ptrdiff_t difference_type β€” the difference type, literally ptrdiff_t πŸ’…
  • typedef _Base::iterator iterator β€” the iterator iterator, no cap 🌸
  • typedef _Alloc_traits::pointer pointer β€” just pointer, we been knew πŸ”₯
  • typedef _Alloc_traits::reference reference β€” reference, the non-const one, periodt πŸ‘‘
  • typedef std::reverse_iterator< iterator > reverse_iterator β€” the backwards-walking iterator, so fetch 🌈
  • typedef size_t size_type β€” size_t, for all your size-related needs ⭐
  • typedef _Tp value_type β€” value_type = _Tp, the actual element, the moment πŸ’œ

πŸ’… Public Member Functions πŸ’…

Constructor time, bestie β€” there are so many ways to build your deque and we're gonna go through every single one 🫢

  • deque ()=default β€” Creates a deque with no elements. Empty queen, zero notes πŸ’…
  • template<typename _InputIterator , typename = std::_RequireInputIter<_InputIterator>> deque (_InputIterator __first, _InputIterator __last, const allocator_type &__a=allocator_type()) β€” Builds a deque from a range. Give her __first to __last and she eats πŸ’–
  • deque (const allocator_type &__a) β€” Creates a deque with no elements. Still empty, but with your allocator 🌸
  • 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. Same vibe, different allocator, we love a remix πŸŽ€
  • deque (deque &&)=default β€” Deque move constructor. She's moving, don't ask where 😭
  • deque (deque &&__x, const __type_identity_t< allocator_type > &__a) β€” Move constructor with alternative allocator. Moving and swapping allocators, versatile icon πŸ¦‹
  • deque (initializer_list< value_type > __l, const allocator_type &__a=allocator_type()) β€” Builds a deque from an initializer list. Curly braces gang, rise 🫢
  • deque (size_type __n, const allocator_type &__a=allocator_type()) β€” Creates a deque with default constructed elements. __n of them, freshly default-constructed πŸ’«
  • deque (size_type __n, const value_type &__value, const allocator_type &__a=allocator_type()) β€” Creates a deque with copies of an exemplar element. __n copies of __value, the blueprint, the prototype πŸ‘‘
  • ~deque () β€” the destructor, she says bye cleanly πŸ’€
  • template<typename _InputIterator , typename = std::_RequireInputIter<_InputIterator>> void assign (_InputIterator __first, _InputIterator __last) β€” Assigns a range to a deque. __first to __last, take it away 🌈
  • void assign (initializer_list< value_type > __l) β€” Assigns an initializer list to a deque. __l gets the job πŸŽ€
  • void assign (size_type __n, const value_type &__val) β€” Assigns a given value to a deque. __n bootlegs of __val 🌸
  • reference at (size_type __n) β€” Provides access to the data contained in the deque. Index __n, please behave 🫢
  • const_reference at (size_type __n) const β€” Provides access to the data contained in the deque. Same deal, but const-flavoured ✨
  • const_reference back () const noexcept β€” the const back, no cap πŸ’œ
  • reference back () noexcept β€” the mutable back, she's there πŸ”₯
  • const_iterator begin () const noexcept β€” const begin πŸ¦‹
  • iterator begin () noexcept β€” begin, but make it mutable ⭐
  • const_iterator cbegin () const noexcept β€” the c-flavoured begin, unbothered πŸ’…
  • const_iterator cend () const noexcept β€” the c-flavoured end 🌸
  • void clear () noexcept β€” wipe her clean, no drama πŸŽ€
  • const_reverse_iterator crbegin () const noexcept β€” const reverse begin, backwards and blessed 🌈
  • const_reverse_iterator crend () const noexcept β€” const reverse end, still going backwards πŸ’«
  • template<typename... _Args> iterator emplace (const_iterator __position, _Args &&... __args) β€” Inserts an object in deque before specified iterator. Builds it in place at __position, efficient queen πŸ‘‘
  • template<typename... _Args> reference emplace_back (_Args &&... __args) β€” emplaces at the back, construct-in-place behaviour 🫢
  • template<typename... _Args> reference emplace_front (_Args &&... __args) β€” emplaces at the front, same energy, other end ✨
  • bool empty () const noexcept β€” is she empty? noexcept about it πŸ’…
  • const_iterator end () const noexcept β€” const end πŸ¦‹
  • iterator end () noexcept β€” mutable end 🌸
  • iterator erase (const_iterator __first, const_iterator __last) β€” Remove a range of elements. __first to __last, gone girl πŸ’€
  • iterator erase (const_iterator __position) β€” Remove element at given position. Just the one, at __position 😭
  • const_reference front () const noexcept β€” const front, the first one πŸŽ€
  • reference front () noexcept β€” mutable front, main character at index zero πŸ‘‘
  • allocator_type get_allocator () const noexcept β€” Get a copy of the memory allocation object. A copy, bestie, not the original πŸ”₯
  • iterator insert (const_iterator __p, initializer_list< value_type > __l) β€” Inserts an initializer list into the deque. At __p, with __l 🌈
  • template<typename _InputIterator , typename = std::_RequireInputIter<_InputIterator>> iterator insert (const_iterator __position, _InputIterator __first, _InputIterator __last) β€” Inserts a range into the deque. __position first, then __first through __last ⭐
  • iterator insert (const_iterator __position, const value_type &__x) β€” Inserts given value into deque before specified iterator. __x goes in before __position πŸ’œ
  • iterator insert (const_iterator __position, size_type __n, const value_type &__x) β€” Inserts a number of copies of given data into the deque. __n copies of __x at __position 🫢
  • iterator insert (const_iterator __position, value_type &&__x) β€” Inserts given rvalue into deque before specified iterator. Rvalue edition, move it along ✨
  • size_type max_size () const noexcept β€” the maximum size, noexcept and unbothered πŸŽ€
  • deque & operator= (const deque &__x) β€” Deque assignment operator. Copy-assign, twin check πŸ’…
  • deque & operator= (deque &&__x) noexcept(_Alloc_traits::_S_always_equal()) β€” Deque move assignment operator. Note the noexcept(_Alloc_traits::_S_always_equal()) β€” that's conditional noexcept, she's fancy πŸ¦‹
  • deque & operator= (initializer_list< value_type > __l) β€” Assigns an initializer list to a deque. Curly braces to the rescue 🌸
  • const_reference operator[] (size_type __n) const noexcept β€” Subscript access to the data contained in the deque. Const flavour, noexcept ⭐
  • reference operator[] (size_type __n) noexcept β€” Subscript access to the data contained in the deque. Mutable flavour, noexcept πŸ”₯
  • void pop_back () noexcept β€” Removes last element. Bye bestie at the back πŸ’€
  • void pop_front () noexcept β€” Removes first element. Bye bestie at the front 😭
  • void push_back (const value_type &__x) β€” Add data to the end of the deque. __x at the back 🫢
  • void push_back (value_type &&__x) β€” push_back but the rvalue one πŸ’«
  • void push_front (const value_type &__x) β€” Add data to the front of the deque. __x at the front πŸ‘‘
  • void push_front (value_type &&__x) β€” push_front but the rvalue one 🌈
  • const_reverse_iterator rbegin () const noexcept β€” const reverse begin πŸŽ€
  • reverse_iterator rbegin () noexcept β€” mutable reverse begin 🌸
  • const_reverse_iterator rend () const noexcept β€” const reverse end πŸ¦‹
  • reverse_iterator rend () noexcept β€” mutable reverse end ⭐
  • void resize (size_type __new_size) β€” Resizes the deque to the specified number of elements. __new_size, that's the number πŸ’œ
  • void resize (size_type __new_size, const value_type &__x) β€” Resizes the deque to the specified number of elements. Same __new_size, and this one takes __x too ✨
  • void shrink_to_fit () noexcept β€” she shrinks to fit, noexcept about it πŸ’…
  • size_type size () const noexcept β€” how many elements? This many 🫢
  • void swap (deque &__x) noexcept β€” Swaps data with another deque. Trading places with __x, noexcept 🌈

πŸ¦‹ Protected Types πŸ¦‹

  • enum { _S_initial_map_size } β€” an enum with _S_initial_map_size in it, the initial map size vibe πŸŽ€
  • typedef __gnu_cxx::__alloc_traits< _Map_alloc_type > _Map_alloc_traits β€” alloc traits for the map alloc type, very internal, very demure 🌸
  • typedef _Alloc_traits::template rebind< _Ptr >::other _Map_alloc_type β€” a rebind to _Ptr, giving _Map_alloc_type πŸ’«
  • typedef _Alloc_traits::pointer _Ptr β€” _Ptr, the pointer alias ⭐
  • typedef _Alloc_traits::const_pointer _Ptr_const β€” _Ptr_const, the const pointer alias πŸ”₯

🌈 Protected Member Functions 🌈

The internals, bestie β€” this is the engine room, no cap πŸ’ͺ

  • template<typename _ForwardIterator > void _M_assign_aux (_ForwardIterator __first, _ForwardIterator __last, std::forward_iterator_tag) β€” the forward-iterator flavour of _M_assign_aux πŸ¦‹
  • template<typename _InputIterator > void _M_assign_aux (_InputIterator __first, _InputIterator __last, std::input_iterator_tag) β€” the input-iterator flavour of _M_assign_aux 🌸
  • void _M_deallocate_map (_Map_pointer __p, size_t __n) noexcept β€” deallocates a map, __p and __n, noexcept πŸŽ€
  • void _M_default_append (size_type __n) β€” default-appends __n of them πŸ’…
  • void _M_default_initialize () β€” default-initializes, the setup moment ✨
  • template<typename _Alloc1 > void _M_destroy_data (iterator __first, iterator __last, const _Alloc1 &) β€” destroy data from __first to __last with an _Alloc1 πŸ’€
  • void _M_destroy_data (iterator __first, iterator __last, const std::allocator< _Tp > &) β€” the std::allocator< _Tp > overload of _M_destroy_data 🌈
  • void _M_destroy_data_aux (iterator __first, iterator __last) β€” the aux version, still destroying data from __first to __last 🫢
  • iterator _M_erase (iterator __first, iterator __last) β€” internal erase over a range ⭐
  • iterator _M_erase (iterator __pos) β€” internal erase at one position πŸ’œ
  • void _M_erase_at_begin (iterator __pos) β€” erase starting at begin, __pos πŸŽ€
  • void _M_erase_at_end (iterator __pos) β€” erase at the end, __pos 🌸
  • void _M_fill_assign (size_type __n, const value_type &__val) β€” fill-assign __n copies of __val πŸ¦‹
  • void _M_fill_initialize (const value_type &__value) β€” Fills the deque with copies of value. __value, over and over ✨
  • void _M_fill_insert (iterator __pos, size_type __n, const value_type &__x) β€” fill-insert __n copies of __x at __pos πŸ’…
  • _Map_alloc_type _M_get_map_allocator () const noexcept β€” hands you a _Map_alloc_type, noexcept πŸŽ€
  • template<typename... _Args> iterator _M_insert_aux (iterator __pos, _Args &&... __args) β€” the aux insert, variadic edition πŸ”₯
  • template<typename _ForwardIterator > void _M_insert_aux (iterator __pos, _ForwardIterator __first, _ForwardIterator __last, size_type __n) β€” aux insert with a forward-iterator range and __n 🌈
  • void _M_insert_aux (iterator __pos, size_type __n, const value_type &__x) β€” aux insert of __n copies of __x at __pos ⭐
  • void _M_move_assign1 (deque &&__x, false_type) β€” move-assign helper, false_type branch πŸ’«
  • void _M_move_assign1 (deque &&__x, true_type) noexcept β€” move-assign helper, true_type branch, noexcept 🫢
  • void _M_move_assign2 (deque &&__x, false_type) β€” the second move-assign helper, false_type 🌸
  • void _M_move_assign2 (deque &&__x, true_type) β€” the second move-assign helper, true_type πŸ¦‹
  • void _M_range_check (size_type __n) const β€” Safety check used only from at(). Only from at(), bestie β€” do not come for her elsewhere πŸ™ˆ
  • template<typename _ForwardIterator > void _M_range_insert_aux (iterator __pos, _ForwardIterator __first, _ForwardIterator __last, std::forward_iterator_tag) β€” range-insert aux, forward-iterator tag flavour πŸŽ€
  • template<typename _InputIterator > void _M_range_insert_aux (iterator __pos, _InputIterator __first, _InputIterator __last, std::input_iterator_tag) β€” range-insert aux, input-iterator tag flavour πŸ’œ
  • template<typename... _Args> void _M_replace_map (_Args &&... __args) β€” replaces the map, variadic args and all ✨
  • bool _M_shrink_to_fit () β€” the bool-returning shrink-to-fit internals πŸ‘‘

🧚 the little nested ones 🧚

These live under _M_shrink_to_fit in the original layout, so here they are, same energy, no elements skipped 🫢

  • template<typename _InputIterator > void _M_range_initialize (_InputIterator __first, _InputIterator __last, std::input_iterator_tag) β€” Fills the deque with whatever is in [first,last). Input-iterator flavour 🌸
  • template<typename _ForwardIterator > void _M_range_initialize (_ForwardIterator __first, _ForwardIterator __last, std::forward_iterator_tag) β€” Fills the deque with whatever is in [first,last). Forward-iterator flavour πŸ¦‹
  • template<typename... _Args> void _M_push_back_aux (_Args &&... __args) β€” Helper functions for push_* and pop_*. Back edition πŸ’«
  • template<typename... _Args> void _M_push_front_aux (_Args &&... __args) β€” Helper functions for push_* and pop_*. Front edition πŸŽ€
  • void _M_pop_back_aux () β€” Helper functions for push_* and pop_*. Popping the back πŸ’€
  • void _M_pop_front_aux () β€” Helper functions for push_* and pop_*. Popping the front 😭
  • iterator _M_reserve_elements_at_front (size_type __n) β€” Memory-handling helpers for the previous internal insert functions. Reserving __n at the front πŸ”₯
  • iterator _M_reserve_elements_at_back (size_type __n) β€” Memory-handling helpers for the previous internal insert functions. Reserving __n at the back 🌈
  • void _M_new_elements_at_front (size_type __new_elements) β€” Memory-handling helpers for the previous internal insert functions. New elements at the front, __new_elements of them ⭐
  • void _M_new_elements_at_back (size_type __new_elements) β€” Memory-handling helpers for the previous internal insert functions. New elements at the back 🫢
  • void _M_reserve_map_at_back (size_type __nodes_to_add=1) β€” Memory-handling helpers for the major map. At the back, default __nodes_to_add=1 πŸ’…
  • void _M_reserve_map_at_front (size_type __nodes_to_add=1) β€” Memory-handling helpers for the major map. At the front, default __nodes_to_add=1 πŸŽ€
  • void _M_reallocate_map (size_type __nodes_to_add, bool __add_at_front) β€” Memory-handling helpers for the major map. __nodes_to_add and __add_at_front, the whole reallocation moment ✨

⭐ Static Protected Member Functions ⭐

  • static size_t _S_check_init_len (size_t __n, const allocator_type &__a) β€” static, so she belongs to the class itself, checking init length with __n and __a πŸ¦‹
  • static size_type _S_max_size (const _Tp_alloc_type &__a) noexcept β€” static max size, noexcept, taking a _Tp_alloc_type πŸ’œ

πŸ’– Detailed Description πŸ’–

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

okay so bestie, this is the container: "A standard container using fixed-size memory allocation and constant-time manipulation of elements at either end." Both ends. Constant time. She's πŸŽ€ iconic πŸŽ€ and she knows it.

🌸 Template Parameters 🌸

  • _Tp β€” Type of element. that's what you're storing, bb.
  • _Alloc β€” Allocator type, defaults to allocator<_Tp>.

She meets the requirements of a container, a reversible container, and a sequence β€” including the optional sequence requirements. overachiever behavior, honestly. πŸ‘‘

⚠️ 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. so yeah πŸ’€ it's gone, don't come looking for it.

🧚 how a deque<Tp> actually manages memory 🧚

ngl this is the part where everyone zones out, but it's lowkey the coolest bit. 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. (and okay, <red>the name map has nothing to do with the std::map class</red>, and "nodes" should not be confused with std::list's usage of node. two totally different vibes, don't mix them up πŸ™ˆ)

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. strategic. deliberate. main character engineering. πŸ’…

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.

✨ Class invariants ✨

these are the rules. break them and everything falls apart. no cap.
  • 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. 😭 confusing but true
    • 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! 🀯 she's living her best life in pieces and doesn't even know it.

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. work smarter not harder, periodt. 🫢


πŸ› οΈ Constructor & Destructor Documentation πŸ› οΈ

πŸ“ deque () [default]

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

Creates a deque with no elements. empty queen, zero notes, nothing to see here ✨

πŸ“ deque (const allocator_type &__a) [inline], [explicit]

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

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()) [inline],  [explicit]

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()) [inline]

Creates a deque with copies of an exemplar element. copy-paste but make it couture πŸ’…

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.

References: std::deque< _Tp, _Alloc >::_M_fill_initialize().

πŸ“ 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) [inline]

Deque copy constructor. the classic twin situation πŸ‘―β€β™€οΈ

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

References: std::deque< _Tp, _Alloc >::begin(), and std::deque< _Tp, _Alloc >::end().

πŸ“ deque (deque< _Tp, _Alloc > &&) [default]

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

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.

⚠️ "valid, but unspecified" is the standard-library way of saying "she's alive but she's not okay, don't look at her." don't go inspecting the moved-from deque, bestie, that's not her job anymore 😭

πŸ“ 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) [inline]

Copy constructor with alternative allocator.

References: std::deque< _Tp, _Alloc >::begin(), and std::deque< _Tp, _Alloc >::end().

πŸ“ 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) [inline]

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()) [inline]

Builds a deque from an initializer list. {1, 2, 3} core, tbh πŸŽ€

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. efficient and organized, we love a planner.

References: std::deque< _Tp, _Alloc >::_M_range_initialize().

πŸ“ 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()) [inline]

Builds a deque from a range. feed her the range and she eats 🍽️

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. read that again, the iterator category literally changes the cost. know your iterators, iykyk πŸ”₯

References: std::__iterator_category(), and std::deque< _Tp, _Alloc >::_M_range_initialize().

πŸ“ ~deque () [inline]

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
std::deque< _Tp, _Alloc >::~deque () [inline]
⚠️ 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. she cleans up her own stuff and only her own stuff. if you put raw pointers in there, that's on you, love πŸ’€

References: std::deque< _Tp, _Alloc >::begin(), and std::deque< _Tp, _Alloc >::end().


πŸ”§ 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) [protected]

Fills the deque with copies of value.

Parameters

  • __value β€” Initial value.

Returns

Nothing.

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, _Alloc >::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) [protected]

Memory-handling helpers for the previous internal insert functions.

References: std::size().

Referenced by: std::deque< _Tp, _Alloc >::_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) [protected]

Memory-handling helpers for the previous internal insert functions.

References: std::size().

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

πŸ’œ _M_pop_back_aux () [protected]

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

Helper functions for push_* and pop_*. the little backstage crew making the magic happen 🎬

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

πŸ’œ _M_pop_front_aux () [protected]

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

Helper functions for push_* and pop_*.

Referenced by: std::deque< _Tp, _Alloc >::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) [protected]

Helper functions for push_* and pop_*. variadic, fancy, obsessed 🫢

References: std::size().

Referenced by: std::deque< _Tp, _Alloc >::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) [protected]

Helper functions for push_* and pop_*.

References: std::size().

Referenced by: std::deque< _Tp, _Alloc >::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 [inline],  [protected]

Safety check used only from at().

References: std::deque< _Tp, _Alloc >::size().

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

🫧 _M_range_initialize (<- the forward-iterator version) [protected]

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

Okay so this one fills the deque with whatever's in [first,last) πŸ’–

  • __first β€” an input iterator, bestie.
  • __last β€” also an input iterator.

Returns: nothing. Nada. Zero. 🫢

Here's the tea: 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.

References std::_Destroy(), std::advance(), and std::distance().


🫧 _M_range_initialize (<- the input-iterator version) [protected]

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

Same deal, fills the deque with whatever's in [first,last) ✨

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

Returns: nothing, again πŸ’…

Same logic, iykyk: if the iterators are actually forward iterators (or better), the memory layout can be done all at once. Else we move forward using push_back on each value from the iterator.

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


πŸ—ΊοΈ _M_reallocate_map [protected]

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 🧚 Makes sure the _M_map has space for new nodes. Does not actually add the nodes β€” it's giving "reserving the table, not seating the guests" energy.

Heads up: this can invalidate _M_map pointers. (And consequently, deque iterators.) So like… don't be holding onto those, bestie 😭

References std::max().

Referenced by std::deque< _Tp, _Alloc >::_M_reserve_map_at_back(), and std::deque< _Tp, _Alloc >::_M_reserve_map_at_front().


πŸŽ€ _M_reserve_elements_at_back [inline], [protected]

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 literally the whole description, she's mysterious like that.

References std::deque< _Tp, _Alloc >::_M_new_elements_at_back().


πŸŽ€ _M_reserve_elements_at_front [inline], [protected]

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

Same vibe, front side πŸ’… Memory-handling helpers for the previous internal insert functions.

References std::deque< _Tp, _Alloc >::_M_new_elements_at_front().


πŸ—ΊοΈ _M_reserve_map_at_back [inline], [protected]

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.

Again: can invalidate _M_map pointers. (And consequently, deque iterators.) Consider yourself warned, gorgeous πŸ™ˆ

Default for __nodes_to_add is 1, for the record.

References std::deque< _Tp, _Alloc >::_M_reallocate_map().


πŸ—ΊοΈ _M_reserve_map_at_front [inline], [protected]

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]

Mirror image, same lore πŸͺž 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.) πŸ’€

__nodes_to_add defaults to 1.

References std::deque< _Tp, _Alloc >::_M_reallocate_map().


πŸ“₯ assign (the iterator-range one) [inline]

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 πŸ’–

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

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

Not me reminding you: the assignment completely changes the deque, and the resulting deque's size is the same as the number of elements assigned πŸ‘‘

References std::__iterator_category().


πŸ“₯ assign (the initializer_list one) [inline]

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 πŸŽ€

  • __l β€” an initializer_list.

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

Same rule as before: the assignment completely changes the deque, and the resulting deque's size is the same as the number of elements assigned ✨

πŸ“₯ assign (the n-copies one) [inline]

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 🌸

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

This function fills a deque with n copies of the given value. Note that the assignment completely changes the deque and that the resulting deque's size is the same as the number of elements assigned πŸ’…


πŸ” at (the read/write one) [inline]

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 🫢

  • __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. It's giving "bouncer at the club checking your ID" energy, lowkey iconic πŸ”₯

References std::deque< _Tp, _Alloc >::_M_range_check().


πŸ” at (the read-only one) [inline]

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

Same function, const era ✨

  • __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 πŸ™ˆ

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.

References std::deque< _Tp, _Alloc >::_M_range_check().


πŸ”š back (const) [inline], [noexcept]

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

Returns a read-only (constant) reference to the data at the last element of the deque πŸ’œ

References std::deque< _Tp, _Alloc >::end().


πŸ”š back (read/write) [inline], [noexcept]

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

Returns a read/write reference to the data at the last element of the deque 🌈

References std::deque< _Tp, _Alloc >::end().


🏁 begin (const) [inline], [noexcept]

template<typename _Tp , typename _Alloc  = std::allocator<_Tp>>
    const_iterator std::deque< _Tp, _Alloc >::begin () 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.


🏁 begin (read/write) [inline], [noexcept]

template<typename _Tp , typename _Alloc  = std::allocator<_Tp>> iterator
    std::deque< _Tp, _Alloc >::begin () [inline],  [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, _Alloc >::deque(), std::deque< _Tp, _Alloc >::deque(), std::deque< _Tp, _Alloc >::~deque(), std::deque< _Tp, _Alloc >::clear(), std::deque< _Tp, _Alloc >::front(), std::deque< _Tp, _Alloc >::front(), std::deque< _Tp, _Alloc >::insert(), std::deque< _Tp, _Alloc >::insert(), std::deque< _Tp, _Alloc >::insert(), std::operator<=>(), and std::deque< _Tp, _Alloc >::operator=().


🏁 cbegin [inline], [noexcept]

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, _Alloc >::insert(), std::deque< _Tp, _Alloc >::insert(), and std::deque< _Tp, _Alloc >::insert().


🏁 cend [inline], [noexcept]

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.


🧹 clear [inline], [noexcept]

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

Erases all the elements 🧼

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. Like, you gotta clean up your own mess, bestie πŸ˜­πŸ’€

References std::deque< _Tp, _Alloc >::begin().


πŸ”„ crbegin [inline], [noexcept]

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


πŸ”„ crend [inline], [noexcept]

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.


✨ 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 the specified iterator πŸŽ€

  • __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's giving "build it right there, main character energy" ✨

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


🫧 empty [inline], [noexcept]

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

Returns true if the deque is empty 😌 (Thus begin() would equal end().) Simple, iconic, does exactly what it says.


🏁 end (const) [inline], [noexcept]

template<typename _Tp , typename _Alloc  = std::allocator<_Tp>>
    const_iterator std::deque< _Tp, _Alloc >::end () 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.


🏁 end (read/write) [inline], [noexcept]

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

Returns a read/write iterator that points one past the last element in the deque 🌈 Iteration is done in ordinary element order.

Referenced by std::deque< _Tp, _Alloc >::deque(), std::deque< _Tp, _Alloc >::deque(), std::deque< _Tp, _Alloc >::~deque(), std::deque< _Tp, _Alloc >::back(), std::deque< _Tp, _Alloc >::back(), std::operator<=>(), and std::deque< _Tp, _Alloc >::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]

bestie this is the "yeet a whole chunk at once" one. Remove a range of elements, gone, bye. Marked [inline], obviously.

Parameters

  • __first β€” iterator pointing to the first element to be erased (the start of the vibe removal).
  • __last β€” iterator pointing to one past the last element to be erased. one PAST, ok, classic half-open range energy.

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 deque accordingly.

⚠️ the user is cautioned β€” and like, pay attention bestie β€” 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. 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 (1) element. singular. [inline].

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. literally minus one, that's the whole bit.

⚠️ same caution as above, and it is not a vibe to skip it: this 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 β€” the const one 🌸

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

Returns a read-only (constant) reference to the data at the first element of the deque. like, look, don't touch. [inline] and [noexcept] because she's reliable like that.

References std::deque< _Tp, _Alloc >::begin().


front β€” the non-const one 🌸✨

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

Returns a read/write reference to the data at the first element of the deque. now you can touch. go off. [inline], [noexcept].

References std::deque< _Tp, _Alloc >::begin().


get_allocator πŸŽ€

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

Get a copy of the memory allocation object. a copy, bestie, not the actual one. [inline], [noexcept].

Referenced by std::deque< _Tp, _Alloc >::operator=().


insert β€” initializer_list flavour πŸ¦‹

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 go brrr. [inline].

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. iconique behaviour honestly.

References std::deque< _Tp, _Alloc >::begin(), and std::deque< _Tp, _Alloc >::cbegin().


insert β€” range flavour 🌈

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. yes the template signature is long, no we are not scared of it. [inline].

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.

References std::__iterator_category(), std::deque< _Tp, _Alloc >::begin(), and std::deque< _Tp, _Alloc >::cbegin().


insert β€” single value, lvalue flavour πŸ’œ

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. the classic. the original. the main character.

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.


insert β€” n copies flavour ⭐

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. like copy-paste but make it ~~fetch~~ legit. [inline].

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.

References std::deque< _Tp, _Alloc >::begin(), and std::deque< _Tp, _Alloc >::cbegin().


insert β€” rvalue flavour πŸ”₯

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. yes it takes && β€” she's moving, she's efficient, she ate. [inline].

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.

References std::deque< _Tp, _Alloc >::emplace(), and std::move().


max_size πŸ‘‘

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

Returns the size() of the largest possible deque. that's it. that's the whole function. [inline], [noexcept], unbothered, moisturized, in her lane.


operator= β€” copy assignment πŸŽ€πŸ’–

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

Deque assignment operator. the copy one.

Parameters

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

All the elements of x are copied. every single one, bestie.

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

References std::__addressof(), std::deque< _Tp, _Alloc >::begin(), std::deque< _Tp, _Alloc >::end(), std::deque< _Tp, _Alloc >::get_allocator(), std::deque< _Tp, _Alloc >::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. [inline], [noexcept] β€” she is not throwing, she's built different.

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. like she's fine but she's not the same girl anymore, don't ask her questions.

References std::move().


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. {a, b, c} and boom, new deque. [inline].

Parameters

  • __l β€” an initializer_list.

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

πŸ’… note β€” the assignment completely changes the deque, and the resulting deque's size() is the same as the number of elements assigned. like a full glow-up, no remnants of before, periodt.

operator[] β€” the const one πŸŒΈπŸ”

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

Subscript access to the data contained in the deque. read-only, look but don't touch. [inline], [noexcept].

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. note β€” data access with this operator is unchecked and out_of_range lookups are not defined. (for checked lookups see at().) 🫢


operator[] β€” the non-const one πŸŒΈπŸ”βœ¨

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

Subscript access to the data contained in the deque. this one you can write to. [inline], [noexcept].

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. note β€” data access with this operator is unchecked and out_of_range lookups are not defined. (for checked lookups see at().) πŸ’€ keep that in mind fr.


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. [inline], [noexcept].

note that no data is returned, and if the last element's data is needed, it should be retrieved before pop_back() is called. like grab the tea before you yeet the cup, bestie. 😭

References std::deque< _Tp, _Alloc >::_M_pop_back_aux().


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. [inline], [noexcept].

note that no data is returned, and if the first element's data is needed, it should be retrieved before pop_front() is called. same rule, other end. πŸ™ˆ

References std::deque< _Tp, _Alloc >::_M_pop_front_aux().


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. [inline].

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. and here's the slay part: due to the nature of a deque this operation can be done in constant time. ⚑

References std::deque< _Tp, _Alloc >::_M_push_back_aux().


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. [inline].

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. yes both ends, that's literally the whole point of her. πŸ‘‘

References std::deque< _Tp, _Alloc >::_M_push_front_aux().


rbegin β€” const πŸ¦‹

template<typename _Tp , typename _Alloc  = std::allocator<_Tp>>
      const_reverse_iterator std::deque< _Tp, _Alloc >::rbegin () 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. yes she goes backwards and she does it flawlessly. [inline], [noexcept].


rbegin β€” non-const πŸ¦‹πŸ’…

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

Returns a read/write reverse iterator that points to the last element in the deque. iteration is done in reverse element order. now you can also write, backwards, in heels. [inline], [noexcept].


rend β€” const 🌈

template<typename _Tp , typename _Alloc  = std::allocator<_Tp>>
      const_reverse_iterator std::deque< _Tp, _Alloc >::rend () 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. yes, one before the first β€” that's not a typo, that's just how reverse iterators coordinate their fit. [inline], [noexcept]. πŸ’œ

✨ rend() ✨

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

Ok bestie, reverse-iterator moment πŸ’… This returns a read/write reverse iterator that points to one before the first element in the deque. Iteration is done in reverse element order. No cap. πŸ¦‹


✨ resize() β€” the one-argument version ✨

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

Resizes the deque to the specified number of elements. Iconic resize behavior, fr fr.

  • __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. References std::deque< _Tp, _Alloc >::size(). πŸ’–


✨ resize() β€” the two-argument version ✨

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

Same resize energy, but now with data to copy into the new spots. Obsessed. πŸŽ€

  • __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 the given data. References std::deque< _Tp, _Alloc >::size(). 🫢


✨ 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 giving "hey bestie, maybe free some space?" β€” but non-binding, so it's a request, not a promise. πŸ’…


✨ size() ✨

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

Returns the number of elements in the deque. Simple, clean, main character energy. ⭐

Referenced by std::deque< _Tp, _Alloc >::_M_range_check(), std::operator<=>(), std::deque< _Tp, _Alloc >::operator=(), std::deque< _Tp, _Alloc >::resize(), and std::deque< _Tp, _Alloc >::resize(). Yes, resize() shows up twice in that list β€” not me double-checking, that's just the original, bestie. πŸ™ˆ


✨ swap() ✨

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

Swaps data with another deque. Trade offer: you get my elements, I get yours. πŸ”₯

  • __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. That part is literally doing its own thing, iykyk. πŸ’œ


✨ Author ✨

Generated automatically by Doxygen for libstdc++ from the source code. πŸ€–βœ¨


That's the whole page, bestie 🫢 Footer source/version + date-line vibes: libstdc++ and std::deque< _Tp, _Alloc >(3cxx). Periodt. πŸ’…πŸŒΈ

πŸ“¦ where this page comes from