---
name: "std::vector"
section: "3cxx"
platform: "linux"
package: "libstdc++-12-doc"
version: "12.4.0-5"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/std::vector/3cxx"
---

# std::vector(3cxx)

A standard container which offers fixed time access to individual elements in any order.

## NAME

std::vector\< \_Tp, \_Alloc \> - A standard container which offers fixed time access to individual elements in any order.

## SYNOPSIS

`#include <vector>`

Inherits **std::\_Vector\_base\< \_Tp, \_Alloc \>**.

Inherited by **std::match\_results\< \_Bi\_iter, \_Alloc \>**` [private]`.

### Public Types

**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

**vector** ()=**default**\
 Creates a vector with no elements.  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.  constexpr **vector** (const **vector** &\_\_x)\
 Vector copy constructor.  constexpr **vector** (const **vector** &\_\_x, const **\_\_type\_identity\_t**\< allocator\_type \> &\_\_a)\
 Copy constructor with 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.  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 alternative allocator.  constexpr **~vector** () noexcept\
 template\<typename... \_Args\> constexpr **auto** **\_M\_emplace\_aux** (const\_iterator **\_\_position**, **\_Args** &&... **\_\_args**) -\> iterator\
 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.  constexpr const\_reference **back** () const noexcept\
 constexpr reference **back** () noexcept\
 constexpr const\_iterator **begin** () const noexcept\
 constexpr iterator **begin** () noexcept\
 constexpr size\_type **capacity** () const noexcept\
 constexpr const\_iterator **cbegin** () const noexcept\
 constexpr const\_iterator **cend** () const noexcept\
 constexpr **void** **clear** () noexcept\
 constexpr **const\_reverse\_iterator** **crbegin** () const noexcept\
 constexpr **const\_reverse\_iterator** **crend** () const noexcept\
 constexpr const \_Tp \* **data** () const noexcept\
 constexpr \_Tp \* **data** () noexcept\
 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**)\
 constexpr bool **empty** () const noexcept\
 constexpr const\_iterator **end** () const noexcept\
 constexpr iterator **end** () noexcept\
 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\
 constexpr reference **front** () noexcept\
 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\
 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)\
 constexpr **const\_reverse\_iterator** **rbegin** () const noexcept\
 constexpr **reverse\_iterator** **rbegin** () noexcept\
 constexpr **const\_reverse\_iterator** **rend** () const noexcept\
 constexpr **reverse\_iterator** **rend** () noexcept\
 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** ()\
 constexpr size\_type **size** () const noexcept\
 constexpr **void** **swap** (**vector** &\_\_x) noexcept\
 Swaps data with another vector.

### Protected Member Functions

constexpr pointer **\_M\_allocate** (size\_t \_\_n)\
 template\<**typename** **\_ForwardIterator** \> constexpr pointer **\_M\_allocate\_and\_copy** (size\_type \_\_n, **\_ForwardIterator** \_\_first, **\_ForwardIterator** \_\_last)\
 template\<**typename** **\_ForwardIterator** \> constexpr **void** **\_M\_assign\_aux** (**\_ForwardIterator** \_\_first, **\_ForwardIterator** \_\_last, **std::forward\_iterator\_tag**)\
 template\<**typename** **\_InputIterator** \> constexpr **void** **\_M\_assign\_aux** (**\_InputIterator** \_\_first, **\_InputIterator** \_\_last, **std::input\_iterator\_tag**)\
 template\<**typename** **\_InputIterator** \> constexpr **void** **\_M\_assign\_dispatch** (**\_InputIterator** \_\_first, **\_InputIterator** \_\_last, \_\_false\_type)\
 template\<**typename** **\_Integer** \> constexpr **void** **\_M\_assign\_dispatch** (**\_Integer** \_\_n, **\_Integer** \_\_val, \_\_true\_type)\
 constexpr size\_type **\_M\_check\_len** (size\_type \_\_n, const char \***\_\_s**) const\
 constexpr **void** **\_M\_create\_storage** (size\_t \_\_n)\
 constexpr **void** **\_M\_deallocate** (pointer \_\_p, size\_t \_\_n)\
 constexpr **void** **\_M\_default\_append** (size\_type \_\_n)\
 constexpr **void** **\_M\_default\_initialize** (size\_type \_\_n)\
 template\<typename... \_Args\> constexpr iterator **\_M\_emplace\_aux** (const\_iterator **\_\_position**, **\_Args** &&... **\_\_args**)\
 constexpr iterator **\_M\_emplace\_aux** (const\_iterator **\_\_position**, value\_type &&**\_\_v**)\
 constexpr iterator **\_M\_erase** (iterator \_\_first, iterator \_\_last)\
 constexpr iterator **\_M\_erase** (iterator **\_\_position**)\
 constexpr **void** **\_M\_erase\_at\_end** (pointer **\_\_pos**) noexcept\
 constexpr **void** **\_M\_fill\_assign** (size\_type \_\_n, const value\_type &\_\_val)\
 constexpr **void** **\_M\_fill\_initialize** (size\_type \_\_n, const value\_type &\_\_value)\
 constexpr **void** **\_M\_fill\_insert** (iterator **\_\_pos**, size\_type \_\_n, const value\_type &\_\_x)\
 constexpr const \_Tp\_alloc\_type & **\_M\_get\_Tp\_allocator** () const noexcept\
 constexpr \_Tp\_alloc\_type & **\_M\_get\_Tp\_allocator** () noexcept\
 template\<**typename** \_Arg \> constexpr **void** **\_M\_insert\_aux** (iterator **\_\_position**, \_Arg &&\_\_arg)\
 template\<**typename** **\_InputIterator** \> constexpr **void** **\_M\_insert\_dispatch** (iterator **\_\_pos**, **\_InputIterator** \_\_first, **\_InputIterator** \_\_last, \_\_false\_type)\
 template\<**typename** **\_Integer** \> constexpr **void** **\_M\_insert\_dispatch** (iterator **\_\_pos**, **\_Integer** \_\_n, **\_Integer** \_\_val, \_\_true\_type)\
 constexpr iterator **\_M\_insert\_rval** (const\_iterator **\_\_position**, value\_type &&**\_\_v**)\
 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**)\
 template\<**typename** **\_InputIterator** \> constexpr **void** **\_M\_range\_initialize** (**\_InputIterator** \_\_first, **\_InputIterator** \_\_last, **std::input\_iterator\_tag**)\
 template\<**typename** **\_ForwardIterator** \> constexpr **void** **\_M\_range\_insert** (iterator **\_\_pos**, **\_ForwardIterator** \_\_first, **\_ForwardIterator** \_\_last, **std::forward\_iterator\_tag**)\
 template\<**typename** **\_InputIterator** \> constexpr **void** **\_M\_range\_insert** (iterator **\_\_pos**, **\_InputIterator** \_\_first, **\_InputIterator** \_\_last, **std::input\_iterator\_tag**)\
 template\<typename... \_Args\> constexpr **void** **\_M\_realloc\_insert** (iterator **\_\_position**, **\_Args** &&... **\_\_args**)\
 constexpr bool **\_M\_shrink\_to\_fit** ()\

### Static Protected Member Functions

**static** constexpr size\_type **\_S\_check\_init\_len** (size\_type \_\_n, const allocator\_type &\_\_a)\
 **static** constexpr size\_type **\_S\_max\_size** (const \_Tp\_alloc\_type &\_\_a) noexcept\

### Protected Attributes

\_Vector\_impl **\_M\_impl**\

## Detailed Description

### template\<typename \_Tp, typename \_Alloc = std::allocator\<\_Tp\>\>

class std::vector\< \_Tp, \_Alloc \>"A standard container which offers fixed time access to individual elements in any order.

**Since**

C++98

**Template Parameters**

*\_Tp* Type of element. \
 *\_Alloc* Allocator type, defaults to allocator\<\_Tp\>.

Meets the requirements of a `container`, a `reversible container`, and a `sequence`, including the `optional sequence requirements` with the exception of `push_front` and `pop_front`.

In some terminology a vector can be described as a dynamic C-style array, it offers fast and efficient access to individual elements in any order and saves the user from worrying about memory and size allocation. Subscripting ( \[\] ) access is also provided as with C-style arrays.

## Constructor & Destructor Documentation

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

Creates a vector with no elements.

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

**Parameters**

*\_\_a* An allocator object.

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

### 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*.

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

The newly-created vector uses a copy of the allocator object used by *\_\_x* (unless the allocator traits dictate a different object).

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

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

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

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

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

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

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

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.

References **std::\_\_iterator\_category()**.

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

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.

References **std::\_Destroy()**.

## Member Function Documentation

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

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

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

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

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

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

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

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

References **std::vector\< \_Tp, \_Alloc \>::\_M\_range\_check()**.

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

References **std::vector\< \_Tp, \_Alloc \>::\_M\_range\_check()**.

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

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

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

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

Referenced by **std::piecewise\_constant\_distribution\< \_RealType \>::max()**, and **std::piecewise\_linear\_distribution\< \_RealType \>::max()**.

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

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

Referenced by **std::vector\< \_Tp, \_Alloc \>::vector()**, **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()**, **std::vector\< \_Tp, \_Alloc \>::rend()**, and **std::vector\< \_Tp, \_Alloc \>::rend()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> constexpr size\_type std::vector\< \_Tp, \_Alloc \>::capacity () const` [inline]`, ` [constexpr]`, ` [noexcept]`

Returns the total number of elements that the vector can hold before needing to allocate more memory.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> constexpr const\_iterator std::vector\< \_Tp, \_Alloc \>::cbegin () 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.

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

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

Returns a read-only (constant) iterator that points one past the last element in the vector. Iteration is done in ordinary element order.

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

Erases all the elements. Note that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.

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

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

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

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

### 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. For a non-empty vector, data() == &front().

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

**Parameters**

*\_\_position* A const\_iterator into the vector. \
 *\_\_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. 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.

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

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

### 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. Iteration is done in ordinary element order.

### 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 is done in ordinary element order.

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::vector\< \_Tp, \_Alloc \>::push\_back()**, **std::vector\< \_Tp, \_Alloc \>::rbegin()**, **std::vector\< \_Tp, \_Alloc \>::rbegin()**, and **std::vector\< \_Tp, \_Alloc \>::resize()**.

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

**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, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.

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

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

**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 that 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.

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

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

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

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

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

Referenced by **std::piecewise\_constant\_distribution\< \_RealType \>::min()**, and **std::piecewise\_linear\_distribution\< \_RealType \>::min()**.

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

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

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

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

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

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

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

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

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

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

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

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

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

### 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. \

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> constexpr vector & std::vector\< \_Tp, \_Alloc \>::operator= (const vector\< \_Tp, \_Alloc \> & \_\_x)` [constexpr]`

Vector assignment operator.

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

Whether the allocator is copied depends on the allocator traits.

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

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

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

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

Whether the allocator is moved depends on the allocator traits.

References **std::move()**.

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

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

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

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

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

Note that no data is returned, and if the last element's data is needed, it should be retrieved before pop\_back() is called.

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

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

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

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

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

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

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

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

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

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

### template\<typename \_Tp , typename \_Alloc \> constexpr void vector::reserve (size\_type \_\_n)` [constexpr]`

Attempt to preallocate enough memory for specified number of elements.

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

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.

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

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

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

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

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

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

### 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. \

Referenced by **std::vector\< \_Tp, \_Alloc \>::\_M\_range\_check()**, **std::discrete\_distribution\< \_IntType \>::max()**, **std::vector\< \_Tp, \_Alloc \>::resize()**, and **std::vector\< \_Tp, \_Alloc \>::resize()**.

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

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

## Author

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