STD::VECTOR(3cxx)

πŸ’– std::vector< _Tp, _Alloc > β€” the glow-up manual πŸ’–

okay so bestie, welcome to the std::vector< _Tp, _Alloc >(3cxx) page. This is the iconic standard container that gives you fixed time access to individual elements in any order. periodt. ✨


🌸 NAME 🌸

std::vector< _Tp, _Alloc > β€” a standard container which offers fixed time access to individual elements in any order. That’s the whole name vibe, no cap. 🫢


✨ SYNOPSIS ✨

#include <vector>

Inherits std::_Vector_base< _Tp, _Alloc >.

Inherited by std::match_results< _Bi_iter, _Alloc > [private].

Lowkey important family tree info, bestie. 🌈

πŸŽ€ Public Types πŸŽ€

Here’s the whole type-alias crew, exactly as listed. No skipping, no shrinking the list. πŸ’…

  • typedef _Alloc allocator_type
  • typedef __gnu_cxx::__normal_iterator< const_pointer, vector > 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 __gnu_cxx::__normal_iterator< pointer, vector > iterator
  • typedef _Base::pointer pointer
  • typedef _Alloc_traits::reference reference
  • typedef std::reverse_iterator< iterator > reverse_iterator
  • typedef size_t size_type
  • typedef _Tp value_type

🫢 Public Member Functions 🫢

This is the main-character list, bestie. Every single one is here. πŸ’–

  • vector ()=default β€” creates a vector with no elements. Empty. Clean slate. πŸŽ€
  • template<typename _InputIterator , typename = std::_RequireInputIter<_InputIterator>> constexpr vector (_InputIterator __first, _InputIterator __last, const allocator_type &__a=allocator_type()) β€” builds a vector from a range.
  • constexpr vector (const allocator_type &__a) noexcept β€” creates a vector with no elements. Still empty, but with your allocator energy. ✨
  • constexpr vector (const vector &__x) β€” vector copy constructor.
  • constexpr vector (const vector &__x, const __type_identity_t< allocator_type > &__a) β€” copy constructor with an alternative allocator.
  • constexpr vector (initializer_list< value_type > __l, const allocator_type &__a=allocator_type()) β€” builds a vector from an initializer list.
  • constexpr vector (size_type __n, const allocator_type &__a=allocator_type()) β€” creates a vector with default constructed elements.
  • constexpr vector (size_type __n, const value_type &__value, const allocator_type &__a=allocator_type()) β€” creates a vector with copies of an exemplar element.
  • vector (vector &&) noexcept=default β€” vector move constructor. Move it, don’t copy it. πŸ’…
  • constexpr vector (vector &&__rv, const __type_identity_t< allocator_type > &__m) noexcept(noexcept(vector(std::declval< vector && >(), std::declval< const allocator_type & >(), std::declval< typename _Alloc_traits::is_always_equal >()))) β€” move constructor with an alternative allocator.
  • constexpr ~vector () noexcept β€” the destructor signature, right here. No extra description in the original, bestie. πŸ’€
  • template<typename... _Args> constexpr auto _M_emplace_aux (const_iterator __position, _Args &&... __args) -> iterator β€” signature only in the original.
  • template<typename _InputIterator , typename = std::_RequireInputIter<_InputIterator>> constexpr void assign (_InputIterator __first, _InputIterator __last) β€” assigns a range to a vector.
  • constexpr void assign (initializer_list< value_type > __l) β€” assigns an initializer list to a vector.
  • constexpr void assign (size_type __n, const value_type &__val) β€” assigns a given value to a vector.
  • constexpr reference at (size_type __n) β€” provides access to the data contained in the vector.
  • constexpr const_reference at (size_type __n) const β€” provides access to the data contained in the vector, const flavor. 🧚
  • constexpr const_reference back () const noexcept β€” signature only in the original.
  • constexpr reference back () noexcept β€” signature only in the original.
  • constexpr const_iterator begin () const noexcept β€” signature only in the original.
  • constexpr iterator begin () noexcept β€” signature only in the original.
  • constexpr size_type capacity () const noexcept β€” signature only in the original.
  • constexpr const_iterator cbegin () const noexcept β€” signature only in the original.
  • constexpr const_iterator cend () const noexcept β€” signature only in the original.
  • constexpr void clear () noexcept β€” signature only in the original.
  • constexpr const_reverse_iterator crbegin () const noexcept β€” signature only in the original.
  • constexpr const_reverse_iterator crend () const noexcept β€” signature only in the original.
  • constexpr const _Tp * data () const noexcept β€” signature only in the original.
  • constexpr _Tp * data () noexcept β€” signature only in the original.
  • template<typename... _Args> constexpr iterator emplace (const_iterator __position, _Args &&... __args) β€” inserts an object in vector before specified iterator.
  • template<typename... _Args> constexpr reference emplace_back (_Args &&... __args) β€” signature only in the original.
  • constexpr bool empty () const noexcept β€” signature only in the original.
  • constexpr const_iterator end () const noexcept β€” signature only in the original.
  • constexpr iterator end () noexcept β€” signature only in the original.
  • constexpr iterator erase (const_iterator __first, const_iterator __last) β€” remove a range of elements.
  • constexpr iterator erase (const_iterator __position) β€” remove element at given position.
  • constexpr const_reference front () const noexcept β€” signature only in the original.
  • constexpr reference front () noexcept β€” signature only in the original.
  • constexpr allocator_type get_allocator () const noexcept β€” get a copy of the memory allocation object.
  • template<typename _InputIterator , typename = std::_RequireInputIter<_InputIterator>> constexpr iterator insert (const_iterator __position, _InputIterator __first, _InputIterator __last) β€” inserts a range into the vector.
  • constexpr iterator insert (const_iterator __position, const value_type &__x) β€” inserts given value into vector before specified iterator.
  • constexpr iterator insert (const_iterator __position, initializer_list< value_type > __l) β€” inserts an initializer_list into the vector.
  • constexpr iterator insert (const_iterator __position, size_type __n, const value_type &__x) β€” inserts a number of copies of given data into the vector.
  • constexpr iterator insert (const_iterator __position, value_type &&__x) β€” inserts given rvalue into vector before specified iterator.
  • constexpr size_type max_size () const noexcept β€” signature only in the original.
  • constexpr vector & operator= (const vector &__x) β€” vector assignment operator.
  • constexpr vector & operator= (initializer_list< value_type > __l) β€” vector list assignment operator.
  • constexpr vector & operator= (vector &&__x) noexcept(_Alloc_traits::_S_nothrow_move()) β€” vector move assignment operator.
  • constexpr const_reference operator[] (size_type __n) const noexcept β€” subscript access to the data contained in the vector.
  • constexpr reference operator[] (size_type __n) noexcept β€” subscript access to the data contained in the vector.
  • constexpr void pop_back () noexcept β€” removes last element.
  • constexpr void push_back (const value_type &__x) β€” add data to the end of the vector.
  • constexpr void push_back (value_type &&__x) β€” signature only in the original.
  • constexpr const_reverse_iterator rbegin () const noexcept β€” signature only in the original.
  • constexpr reverse_iterator rbegin () noexcept β€” signature only in the original.
  • constexpr const_reverse_iterator rend () const noexcept β€” signature only in the original.
  • constexpr reverse_iterator rend () noexcept β€” signature only in the original.
  • constexpr void reserve (size_type __n) β€” attempt to preallocate enough memory for specified number of elements.
  • constexpr void resize (size_type __new_size) β€” resizes the vector to the specified number of elements.
  • constexpr void resize (size_type __new_size, const value_type &__x) β€” resizes the vector to the specified number of elements.
  • constexpr void shrink_to_fit () β€” signature only in the original.
  • constexpr size_type size () const noexcept β€” signature only in the original.
  • constexpr void swap (vector &__x) noexcept β€” swaps data with another vector.

πŸ’œ Protected Member Functions πŸ’œ

Protected means the internals are doing their thing behind the scenes, bestie. Every listed signature is still here, fr fr. πŸ¦‹

  • constexpr pointer _M_allocate (size_t __n) β€” signature only in the original.
  • template<typename _ForwardIterator > constexpr pointer _M_allocate_and_copy (size_type __n, _ForwardIterator __first, _ForwardIterator __last) β€” signature only in the original.
  • template<typename _ForwardIterator > constexpr void _M_assign_aux (_ForwardIterator __first, _ForwardIterator __last, std::forward_iterator_tag) β€” signature only in the original.
  • template<typename _InputIterator > constexpr void _M_assign_aux (_InputIterator __first, _InputIterator __last, std::input_iterator_tag) β€” signature only in the original.
  • template<typename _InputIterator > constexpr void _M_assign_dispatch (_InputIterator __first, _InputIterator __last, __false_type) β€” signature only in the original.
  • template<typename _Integer > constexpr void _M_assign_dispatch (_Integer __n, _Integer __val, __true_type) β€” signature only in the original.
  • constexpr size_type _M_check_len (size_type __n, const char *__s) const β€” signature only in the original.
  • constexpr void _M_create_storage (size_t __n) β€” signature only in the original.
  • constexpr void _M_deallocate (pointer __p, size_t __n) β€” signature only in the original.
  • constexpr void _M_default_append (size_type __n) β€” signature only in the original.
  • constexpr void _M_default_initialize (size_type __n) β€” signature only in the original.
  • template<typename... _Args> constexpr iterator _M_emplace_aux (const_iterator __position, _Args &&... __args) β€” signature only in the original.
  • constexpr iterator _M_emplace_aux (const_iterator __position, value_type &&__v) β€” signature only in the original.
  • constexpr iterator _M_erase (iterator __first, iterator __last) β€” signature only in the original.
  • constexpr iterator _M_erase (iterator __position) β€” signature only in the original.
  • constexpr void _M_erase_at_end (pointer __pos) noexcept β€” signature only in the original.
  • constexpr void _M_fill_assign (size_type __n, const value_type &__val) β€” signature only in the original.
  • constexpr void _M_fill_initialize (size_type __n, const value_type &__value) β€” signature only in the original.
  • constexpr void _M_fill_insert (iterator __pos, size_type __n, const value_type &__x) β€” signature only in the original.
  • constexpr const _Tp_alloc_type & _M_get_Tp_allocator () const noexcept β€” signature only in the original.
  • constexpr _Tp_alloc_type & _M_get_Tp_allocator () noexcept β€” signature only in the original.
  • template<typename _Arg > constexpr void _M_insert_aux (iterator __position, _Arg &&__arg) β€” signature only in the original.
  • template<typename _InputIterator > constexpr void _M_insert_dispatch (iterator __pos, _InputIterator __first, _InputIterator __last, __false_type) β€” signature only in the original.
  • template<typename _Integer > constexpr void _M_insert_dispatch (iterator __pos, _Integer __n, _Integer __val, __true_type) β€” signature only in the original.
  • constexpr iterator _M_insert_rval (const_iterator __position, value_type &&__v) β€” signature only in the original.
  • constexpr void _M_range_check (size_type __n) const β€” safety check used only from at().
  • template<typename _ForwardIterator > constexpr void _M_range_initialize (_ForwardIterator __first, _ForwardIterator __last, std::forward_iterator_tag) β€” signature only in the original.
  • template<typename _InputIterator > constexpr void _M_range_initialize (_InputIterator __first, _InputIterator __last, std::input_iterator_tag) β€” signature only in the original.
  • template<typename _ForwardIterator > constexpr void _M_range_insert (iterator __pos, _ForwardIterator __first, _ForwardIterator __last, std::forward_iterator_tag) β€” signature only in the original.
  • template<typename _InputIterator > constexpr void _M_range_insert (iterator __pos, _InputIterator __first, _InputIterator __last, std::input_iterator_tag) β€” signature only in the original.
  • template<typename... _Args> constexpr void _M_realloc_append (_Args &&... __args) β€” signature only in the original.
  • template<typename... _Args> constexpr void _M_realloc_insert (iterator __position, _Args &&... __args) β€” signature only in the original.
  • constexpr bool _M_shrink_to_fit () β€” signature only in the original.

🌟 Static Protected Member Functions 🌟

Static protected internals, still exactly as listed. πŸŽ€

  • static constexpr size_type _S_check_init_len (size_type __n, const allocator_type &__a) β€” signature only in the original.
  • static constexpr size_type _S_max_size (const _Tp_alloc_type &__a) noexcept β€” signature only in the original.

🧚 Protected Attributes 🧚

  • _Vector_impl _M_impl β€” the protected attribute listed in the original. That’s the whole note, no extra lore. πŸ’œ

πŸ“– Detailed Description πŸ“–

okay bestie, settle in, because this is the part where we actually get to know the star of the show πŸ’…

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

It's "A standard container which offers fixed time access to individual elements in any order." β€” like, any order, zero drama, constant time, she simply does not miss πŸ”₯

Since: C++98 (she's an icon, she's been iconic)

πŸŽ€ Template Parameters πŸŽ€

  • _Tp β€” the type of the elements. whatever you're storing, she'll hold it 🫢
  • _Alloc β€” the allocator type, and it defaults to allocator<_Tp>. yes it's optional, no you don't have to touch it, yes it's giving behind-the-scenes main character energy ✨

She meets the requirements of a container, a reversible container, and a sequence β€” and that includes the optional sequence requirements except for push_front and pop_front. like, no front-pushing babe, that's not her thing, go talk to std::deque 😭

In some terminology you could describe a vector as a dynamic C-style array. she gives you fast and efficient access to individual elements in any order, and she saves you from worrying about memory and size allocation entirely β€” not your problem anymore, bestie, she handles it πŸ‘‘ Subscripting ([]) access is also provided, just like with C-style arrays. taste recognizes taste πŸ’…


🧚 Constructor & Destructor Documentation 🧚

okay there are a LOT of these and every single one is valid, let's go number by number because we do NOT skip ✨

⭐ vector() β€” the default one

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

Creates a vector with no elements. empty, fresh, unbothered, moisturized 🌸

⭐ vector(const allocator_type&) β€” empty but with your own allocator

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

Creates a vector with no elements. same vibe as above, she's just carrying your allocator.

Parameters

  • __a β€” an allocator object πŸŽ€

⭐ vector(size_type, const allocator_type&) β€” n default-constructed cuties

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

Creates a vector with default constructed elements.

Parameters

  • __n β€” the number of elements to initially create πŸ”’
  • __a β€” an allocator πŸŽ€

This constructor fills the vector with __n default constructed elements. no cap, __n of them, all freshly defaulted πŸ’œ

⭐ vector(size_type, const value_type&, const allocator_type&) β€” n copies of one vibe

template<typename _Tp , typename _Alloc  = std::allocator<_Tp>> constexpr
    std::vector< _Tp, _Alloc >::vector (size_type __n, const value_type &
    __value, const allocator_type & __a = allocator_type()) [inline],
    [constexpr]

Creates a vector 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 vector with __n copies of __value. she said "I'll have what she's having" Γ— __n πŸ˜­πŸ’…

⭐ copy constructor

template<typename _Tp , typename _Alloc  = std::allocator<_Tp>> constexpr
    std::vector< _Tp, _Alloc >::vector (const vector< _Tp, _Alloc > & __x)
    [inline],  [constexpr]

Vector copy constructor.

Parameters

  • __x β€” a vector of identical element and allocator types πŸ‘―

All the elements of __x are copied, but any unused capacity in __x will not be copied β€” i.e. capacity() == size() in the new vector. she takes the elements, she leaves the extra room, she's not greedy πŸ’€

The newly-created vector uses a copy of the allocator object used by __x (unless the allocator traits dictate a different object). noted, allocator traits get the final say, we respect them 🫢

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

⭐ move constructor

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

Vector move constructor. The newly-created vector contains the exact contents of the moved instance. The contents of the moved instance are a valid, but unspecified vector β€” so like, don't go reading her afterwards, she's fine but she's not yours anymore πŸ™ˆ

⭐ copy constructor, but make it a different allocator

template<typename _Tp , typename _Alloc  = std::allocator<_Tp>> constexpr
    std::vector< _Tp, _Alloc >::vector (const vector< _Tp, _Alloc > & __x,
    const __type_identity_t< allocator_type > & __a) [inline],  [constexpr]

Copy constructor with alternative allocator. same copies, your allocator, slay ✨

⭐ move constructor, but make it a different allocator

template<typename _Tp , typename _Alloc  = std::allocator<_Tp>> constexpr
    std::vector< _Tp, _Alloc >::vector (vector< _Tp, _Alloc > && __rv, const
    __type_identity_t< allocator_type > & __m) [inline],  [constexpr],
    [noexcept]

Move constructor with alternative allocator. moving, but with your allocator this time. iconic behavior honestly πŸ’…

⭐ vector(initializer_list<value_type>, const allocator_type&) β€” the curly-brace one

template<typename _Tp , typename _Alloc  = std::allocator<_Tp>> constexpr
    std::vector< _Tp, _Alloc >::vector (initializer_list< value_type > __l,
    const allocator_type & __a = allocator_type()) [inline],  [constexpr]

Builds a vector from an initializer list. yes the {1, 2, 3} thing, she's right there πŸŽ€

Parameters

  • __l β€” an initializer_list πŸ“
  • __a β€” an allocator πŸŽ€

Create a vector 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 queen behavior, we love to see it πŸ‘‘

⭐ vector(_InputIterator, _InputIterator, const allocator_type&) β€” the range one

template<typename _Tp , typename _Alloc  = std::allocator<_Tp>>
    template<typename _InputIterator , typename  =
    std::_RequireInputIter<_InputIterator>> constexpr std::vector< _Tp,
    _Alloc >::vector (_InputIterator __first, _InputIterator __last, const
    allocator_type & __a = allocator_type()) [inline],  [constexpr]

Builds a vector from a range.

Parameters

  • __first β€” an input iterator 🌸
  • __last β€” an input iterator 🌸
  • __a β€” an allocator πŸŽ€

Create a vector consisting of copies of the elements from [first,last).

Now listen, the efficiency here is iterator-dependent and that's important: 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 basically: give her good iterators and she'll treat you right 🫢

References std::__iterator_category().

⭐ destructor

template<typename _Tp , typename _Alloc  = std::allocator<_Tp>> constexpr
    std::vector< _Tp, _Alloc >::~vector () [inline],  [constexpr],
    [noexcept]

The dtor only erases the elements, and β€” important caveat bestie, read this twice β€” 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 the container, she does not chase your pointers, that's on you πŸ™ˆ

References std::_Destroy().


πŸ’– Member Function Documentation πŸ’–

πŸ”§ _M_allocate_and_copy (protected, don't touch unless you're built different)

template<typename _Tp , typename _Alloc  = std::allocator<_Tp>>
    template<typename _ForwardIterator > constexpr pointer std::vector< _Tp,
    _Alloc >::_M_allocate_and_copy (size_type __n, _ForwardIterator __first,
    _ForwardIterator __last) [inline],  [constexpr],  [protected]

Memory expansion handler. Uses the member allocation function to obtain n bytes of memory, and then copies [first,last) into it. she's a [protected] girlie, she's behind the curtain, she's the whole reason it works πŸ’…

πŸ”§ _M_range_check (protected)

template<typename _Tp , typename _Alloc  = std::allocator<_Tp>> constexpr
    void std::vector< _Tp, _Alloc >::_M_range_check (size_type __n) const
    [inline],  [constexpr],  [protected]

Safety check used only from at(). she's the bouncer at the door, she checks IDs, no exceptions (well β€” exceptions are literally her job, but you know what I mean) πŸŽ€

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

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

✨ assign β€” the range version

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

Assigns a range to a vector.

Parameters

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

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

Note that the assignment completely changes the vector and that the resulting vector's size is the same as the number of elements assigned. not a merge, not an append β€” a full glow-up, she's a different girl now πŸ’…

References std::__iterator_category().

✨ assign β€” the initializer_list version

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

Assigns an initializer list to a vector.

Parameters

  • __l β€” an initializer_list πŸ“

This function fills a vector with copies of the elements in the initializer list __l.

Note that the assignment completely changes the vector and that the resulting vector's size is the same as the number of elements assigned. same deal as before, she's reborn with new content ✨

✨ assign β€” the n-copies-of-val version

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

Assigns a given value to a vector.

Parameters

  • __n β€” number of elements to be assigned πŸ”’
  • __val β€” value to be assigned πŸ“

This function fills a vector with __n copies of the given value. Note that the assignment completely changes the vector and that the resulting vector's size is the same as the number of elements assigned. copies on copies on copies, that's the assignment 😌

πŸ¦‹ at β€” the safe one (non-const)

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

Provides access to the data contained in the vector.

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 vector. The function throws out_of_range if the check fails. she checks before she lets you in, unlike some people ([], we're looking at you πŸ‘€) πŸ’€

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

πŸ¦‹ at β€” same but read-only (const)

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

Provides access to the data contained in the vector.

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 🚨

This function provides for safer data access. The parameter is first checked that it is in the range of the vector. The function throws out_of_range if the check fails. look but don't touch edition, we love a boundaries girlie 🫢

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

🌟 back β€” const version

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

Returns a read-only (constant) reference to the data at the last element of the vector. the final girl, the last one standing πŸ’œ

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

🌟 back β€” non-const version

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

Returns a read/write reference to the data at the last element of the vector. and yes you can write to her, go off πŸ“

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

Referenced by std::piecewise_constant_distribution< _RealType >::max(), and std::piecewise_linear_distribution< _RealType >::max(). look at her, doing cross-header community service πŸ˜­πŸ‘‘

πŸŽ€ begin β€” const version

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

Returns a read-only (constant) iterator that points to the first element in the vector. Iteration is done in ordinary element order. no funny business, just order, front to back 🌸

πŸŽ€ begin β€” non-const version

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

Returns a read/write iterator that points to the first element in the vector. Iteration is done in ordinary element order. go ahead, mutate her, she can take it πŸ’…


Referenced by: std::vector< _Tp, _Alloc >::vector(), std::match_results< _Bi_iter, _Alloc >::begin(), std::vector< _Tp, _Alloc >::crend(), std::vector< _Tp, _Alloc >::empty(), std::vector< _Tp, _Alloc >::erase(), std::vector< _Tp, _Alloc >::erase(), std::vector< _Tp, _Alloc >::front(), std::vector< _Tp, _Alloc >::front(), std::vector< _Tp, _Alloc >::insert(), std::vector< _Tp, _Alloc >::insert(), std::vector< _Tp, _Alloc >::insert(), __gnu_parallel::multiway_merge_exact_splitting(), std::operator<=>(), std::vector< _Tp, _Alloc >::operator=(), std::operator==(), std::vector< _Tp, _Alloc >::rend(), and std::vector< _Tp, _Alloc >::rend().


πŸ’… capacity()

template<typename _Tp , typename _Alloc  = std::allocator<_Tp>> constexpr
    size_type std::vector< _Tp, _Alloc >::capacity () const [inline],
    [constexpr],  [noexcept]

Okay bestie, this one is the how much room do I have check πŸ’–. It hands you back the total number of elements that the vector can hold before needing to allocate more memory. That's it. It's the closet size, not how many outfits are actually in there. ✨


πŸŽ€ cbegin()

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

Gives you a read-only (constant) iterator that points to the first element in the vector. Iteration happens in ordinary element order β€” no fancy business. This is the "look but don't touch" pass πŸ”’

Referenced by: std::vector< _Tp, _Alloc >::erase(), std::vector< _Tp, _Alloc >::erase(), std::vector< _Tp, _Alloc >::insert(), std::vector< _Tp, _Alloc >::insert(), and std::vector< _Tp, _Alloc >::insert().


πŸ¦‹ cend()

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

Same deal as cbegin(), but it's a read-only (constant) iterator that points one past the last element in the vector. Classic one-past-the-end situation, iteration in ordinary element order. It does not point at a real element, bestie β€” it's the finish line, not a runner πŸ’€


🧹 clear()

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

Erases all the elements. Poof, gone, the closet is empty 🌸

Hold up though β€” this function only erases the elements. If the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is your responsibility. Not mine, not the vector's. Yours. 😭

πŸ”„ crbegin()

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

Returns a read-only (constant) reverse iterator that points to the last element in the vector. Iteration is done in reverse element order β€” so you're walking backwards through the fit checks πŸ‘‘

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


πŸ”™ crend()

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

Returns a read-only (constant) reverse iterator that points to one before the first element in the vector. Iteration is done in reverse element order. It's the far end of the backwards walk, don't expect it to dereference to anything πŸ™ˆ

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


🫢 data()

template<typename _Tp , typename _Alloc  = std::allocator<_Tp>> constexpr
    _Tp * std::vector< _Tp, _Alloc >::data () [inline],  [constexpr],
    [noexcept]

Returns a pointer such that [data(), data() + size()) is a valid range. And for a non-empty vector, data() == &front() β€” cute little fact, no cap ✨


πŸͺ„ emplace()

template<typename _Tp , typename _Alloc  = std::allocator<_Tp>>
    template<typename... _Args> constexpr iterator std::vector< _Tp, _Alloc
    >::emplace (const_iterator __position, _Args &&... __args) [inline],
    [constexpr]

Inserts an object in vector before specified iterator. Main character energy for the variadic pack πŸŽ€

Parameters

  • __position β€” A const_iterator into the vector.
  • __args β€” Arguments.

Returns

An iterator that points to the inserted data.

So like, this function will insert an object of type T constructed with T(std::forward<Args>(args)...) before the specified location. Iconic. But note β€” this kind of operation could be expensive for a vector and if it is frequently used the user should consider using std::list. Lowkey a glow-up-with-a-cost situation πŸ’Έ


🫧 empty()

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

Returns true if the vector is empty. (Thus begin() would equal end() β€” vibe check passed βœ…)

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

Referenced by: std::piecewise_constant_distribution< _RealType >::densities(), std::piecewise_linear_distribution< _RealType >::densities(), std::match_results< _Bi_iter, _Alloc >::end(), std::piecewise_constant_distribution< _RealType >::intervals(), std::piecewise_linear_distribution< _RealType >::intervals(), std::discrete_distribution< _IntType >::max(), std::piecewise_constant_distribution< _RealType >::max(), std::piecewise_linear_distribution< _RealType >::max(), std::piecewise_constant_distribution< _RealType >::min(), std::piecewise_linear_distribution< _RealType >::min(), and std::discrete_distribution< _IntType >::probabilities().


🏁 end() (const version)

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

Returns a read-only (constant) iterator that points one past the last element in the vector. Ordinary element order, as always. No touching πŸ’…


🏁 end() (the read/write one)

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

Returns a read/write iterator that points one past the last element in the vector. Iteration in ordinary element order. This is the one you're allowed to mess with πŸ‘‘

Referenced by: std::vector< _Tp, _Alloc >::vector(), std::vector< _Tp, _Alloc >::back(), std::vector< _Tp, _Alloc >::back(), std::vector< _Tp, _Alloc >::crbegin(), std::vector< _Tp, _Alloc >::empty(), std::match_results< _Bi_iter, _Alloc >::end(), __gnu_parallel::multiway_merge_exact_splitting(), std::operator<=>(), std::vector< _Tp, _Alloc >::operator=(), std::operator==(), std::vector< _Tp, _Alloc >::rbegin(), std::vector< _Tp, _Alloc >::rbegin(), and std::vector< _Tp, _Alloc >::resize().


βœ‚οΈ erase() β€” range version

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

Remove a range of elements. Cleaning out a whole section of the closet 🧹

Parameters

  • __first β€” Iterator pointing to the first element to be erased.
  • __last β€” Iterator pointing to one past the last element to be erased.

Returns

An iterator pointing to the element pointed to by __last prior to erasing (or end()).

This function will erase the elements in the range [__first,__last) and shorten the vector accordingly.

Note: This operation could be expensive, and if it is frequently used the user should consider using std::list. The user is also cautioned that 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. Fr fr, that's on you 😭

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


πŸ—‘οΈ erase() β€” single element version

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

Remove element at given position. Just the one, one single element, no group drama πŸ™ˆ

Parameters

  • __position β€” Iterator pointing to element to be erased.

Returns

An iterator pointing to the next element (or end()).

This function will erase the element at the given position and thus shorten the vector by one.

Note: This operation could be expensive, and if it is frequently used the user should consider using std::list. The user is also cautioned that 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. Same warning, bestie, it did not go away πŸ’€

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


πŸ’– front() (const version)

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

Returns a read-only (constant) reference to the data at the first element of the vector. First in line, but you can't change its outfit πŸ”’

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


πŸ’– front() (the read/write one)

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

Returns a read/write reference to the data at the first element of the vector. Now you can change the outfit. Slay πŸŽ€

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

Referenced by: std::piecewise_constant_distribution< _RealType >::min(), and std::piecewise_linear_distribution< _RealType >::min().


🧺 get_allocator()

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

Get a copy of the memory allocation object. That's the whole thing. A little photocopy of the memory manager, for your records 🫢

Referenced by: std::match_results< _Bi_iter, _Alloc >::get_allocator().


πŸ“₯ insert() β€” range version

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

Inserts a range into the vector. Bulk upload energy ✨

Parameters

  • __position β€” A const_iterator into the vector.
  • __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 vector before the location specified by pos.

Note that this kind of operation could be expensive for a vector and if it is frequently used the user should consider using std::list. It's giving "great for vibes, mid for performance" 😭

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


πŸ“₯ insert() β€” single value version

template<typename _Tp , typename _Alloc > constexpr vector< _Tp, _Alloc
    >::iterator vector::insert (const_iterator __position, const value_type
    & __x) [constexpr]

Inserts given value into vector before specified iterator. One (1) little guy, placed with intent πŸ’…

Parameters

  • __position β€” A const_iterator into the vector.
  • __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. Note that this kind of operation could be expensive for a vector and if it is frequently used the user should consider using std::list. You've heard this before, and you'll hear it again πŸ”₯

References: std::begin(), std::cbegin(), std::end(), and std::move().


πŸ“₯ insert() β€” initializer_list version

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

Inserts an initializer_list into the vector. Brace-init besties, this one's for you πŸŽ€

Parameters

  • __position β€” An iterator into the vector.
  • __l β€” An initializer_list.

This function will insert copies of the data in the initializer_list l into the vector before the location specified by position. πŸŽ€

Fair warning bestie: this kind of operation could be expensive for a vector, and if it is frequently used the user should consider using std::list. 😭 fr fr, that's the official advice, not me being dramatic.

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


🌸 insert β€” the "n copies" edition

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

Inserts a number of copies of given data into the vector. πŸ’…

Parameters

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

Note that this kind of operation could be expensive for a vector and if it is frequently used the user should consider using std::list. 🫢

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


πŸ¦‹ insert β€” the rvalue edition

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

Inserts given rvalue into vector before specified iterator. yep, moving-coded πŸ’œ

Parameters

  • __position β€” a const_iterator into the vector.
  • __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. Note that this kind of operation could be expensive for a vector and if it is frequently used the user should consider using std::list. πŸ’€

References: std::move().


⭐ max_size

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

Returns the size() of the largest possible vector. that's the ceiling, the limit, the "no further" 😀


πŸ‘‘ operator= β€” the copy assignment one

template<typename _Tp , typename _Alloc > constexpr vector< _Tp, _Alloc > &
    vector::operator= (const vector< _Tp, _Alloc > & __x) [constexpr]

Vector assignment operator. classic copy-paste-that-vibe energy πŸŽ€

Parameters

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

All the elements of __x are copied, but any unused capacity in __x will not be copied. (only the real ones show up to the party, the empty chairs stay home πŸͺ‘)

Whether the allocator is copied depends on the allocator traits. lowkey important, don't skip that line.

References: std::__addressof(), std::_Destroy(), std::vector< _Tp, _Alloc >::begin(), std::begin(), std::vector< _Tp, _Alloc >::end(), std::end(), std::vector< _Tp, _Alloc >::size(), and std::size().


πŸŽ€ operator= β€” the initializer_list one

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

Vector list assignment operator. so v = {1, 2, 3}; coded 🌈

Parameters

  • __l β€” an initializer_list.

This function fills a vector with copies of the elements in the initializer list __l.

Note that the assignment completely changes the vector and that the resulting vector's size is the same as the number of elements assigned. like, total glow-up, not a single old element survives πŸ’…


πŸ’œ operator= β€” the move assignment one

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

Vector move assignment operator. fast, efficient, no copying 😌

Parameters

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

The contents of __x are moved into this vector (without copying, if the allocators permit it). Afterwards __x is a valid, but unspecified vector. ⚠️ that means "it exists, don't assume anything else about it" β€” she's alive but she's not the same girl.

Whether the allocator is moved depends on the allocator traits.

References: std::move().


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

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

Subscript access to the data contained in the vector. read-only mode, look don't touch πŸ™ˆ

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 that data access with this operator is unchecked and out_of_range lookups are not defined. 😭 (For checked lookups see at().) ngl bestie, unfiltered and unguarded β€” she will not protect you.


🌸 operator[] β€” the non-const one

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

Subscript access to the data contained in the vector. this one you can touch πŸ’…

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 that data access with this operator is unchecked and out_of_range lookups are not defined. 😭 (For checked lookups see at().) same energy, same warning, no cap.


πŸ¦‹ pop_back

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

Removes last element. This is a typical stack operation. It shrinks the vector by one. bye bestie πŸ‘‹

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 info first, because once she's gone she's gone.


✨ push_back β€” the lvalue-ish one

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

Add data to the end of the vector. party's at the back πŸŽ‰

Parameters

  • __x β€” data to be added.

This is a typical stack operation. The function creates an element at the end of the vector and assigns the given data to it. Due to the nature of a vector this operation can be done in constant time if the vector has preallocated space available. πŸ”₯ that "if" is doing a lot of work, keep an eye on it.


🌈 rbegin β€” const version

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

Returns a read-only (constant) reverse iterator that points to the last element in the vector. Iteration is done in reverse element order. going backwards, staying unbothered πŸšΆβ€β™€οΈ

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


⭐ rbegin β€” non-const version

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

Returns a read/write reverse iterator that points to the last element in the vector. Iteration is done in reverse element order. same walk, but you can edit as you go πŸ’…

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


🫢 rend β€” const version

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

Returns a read-only (constant) reverse iterator that points to one before the first element in the vector. Iteration is done in reverse element order. the finish line of the backwards walk 🏁

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


🧚 rend β€” non-const version

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

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

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


πŸ’– reserve

template<typename _Tp , typename _Alloc > constexpr void vector::reserve
    (size_type __n) [constexpr]

Attempt to preallocate enough memory for specified number of elements. planning ahead, main character energy ✨

Parameters

  • __n β€” number of elements required.

Exceptions

  • std::length_error β€” if n exceeds max_size().

This function attempts to reserve enough memory for the vector to hold the specified number of elements. If the number requested is more than max_size(), length_error is thrown. ⚠️ overreaching gets you yeeted.

The advantage of this function is that if optimal code is a necessity and the user can determine the number of elements that will be required, the user can reserve the memory in advance, and thus prevent a possible reallocation of memory and copying of vector data. πŸ”₯ big win, no cap.

References: std::_Destroy(), and std::size().


πŸŽ€ resize β€” the one-argument version

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

Resizes the vector to the specified number of elements. trim or extend, dealer's choice πŸ’…

Parameters

  • __new_size β€” number of elements the vector should contain.

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

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

Referenced by __gnu_parallel::__shrink_and_double(), and __gnu_parallel::multiway_merge_exact_splitting().


πŸ“ resize β€” the two-argument version

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

Resizes the vector to the specified number of elements. but this time the newbies get a whole personality πŸ’œ

Parameters

  • __new_size β€” number of elements the vector should contain.
  • __x β€” data with which new elements should be populated.

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

References: std::vector< _Tp, _Alloc >::end(), and std::vector< _Tp, _Alloc >::size().


πŸ¦‹ shrink_to_fit

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

A non-binding request to reduce capacity() to size(). ⚠️ key word: non-binding β€” she's asking politely, not demanding, so don't be shocked if the capacity lowkey stays the same. πŸ™ˆ


🌟 size

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

Returns the number of elements in the vector. the headcount, the guest list πŸ’…

Referenced by __gnu_parallel::__shrink(), __gnu_parallel::__shrink_and_double(), std::vector< _Tp, _Alloc >::_M_range_check(), __gnu_parallel::list_partition(), std::discrete_distribution< _IntType >::max(), std::vector< _Tp, _Alloc >::operator=(), std::operator==(), std::vector< _Tp, _Alloc >::resize(), and std::vector< _Tp, _Alloc >::resize(). (yes, resize is in there twice, that's literally what the page says 🫠)


🌈 swap

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

Swaps data with another vector. trading lives, iconic behavior πŸ‘‘

Parameters

  • __x β€” a vector of the same element and allocator types.

This exchanges the elements between two vectors in constant time. (Three pointers, so it should be quite fast.) πŸ”₯ Note that the global std::swap() function is specialized such that std::swap(v1,v2) will feed to this function.

Whether the allocators are swapped depends on the allocator traits. lowkey load-bearing detail, don't sleep on it.

Referenced by std::match_results< _Bi_iter, _Alloc >::swap().

✨ AUTHOR ✨

So like, nobody actually wrote this page with their human hands, bestie β€” it was generated automatically by Doxygen for libstdc++ from the source code. The docs robot did its little thing and spat this whole page out. Iconic behaviour honestly 🫢


And that's the whole page, babes! πŸŽ€ You made it to the end β€” main character energy fr fr πŸ’…

This little masterpiece lives in the libstdc++ docs, filed under the extremely long and fancy name std::vector< _Tp, _Alloc >(3cxx), and it was auto-generated by Doxygen straight from the source code β€” no cap, not a single human typed it 😭✨

Now go forth and push_back responsibly, bestie πŸŒΈπŸ¦‹πŸ’–

πŸ“¦ where this page comes from