- tmp/tmp723rqss9/{from.md → to.md} +101 -82
tmp/tmp723rqss9/{from.md → to.md}
RENAMED
|
@@ -1,64 +1,62 @@
|
|
| 1 |
### Class template `vector` <a id="vector">[[vector]]</a>
|
| 2 |
|
| 3 |
#### Class template `vector` overview <a id="vector.overview">[[vector.overview]]</a>
|
| 4 |
|
| 5 |
-
A `vector` is a sequence container that supports
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
given to improve efficiency. The elements of a vector are stored
|
| 10 |
-
contiguously, meaning that if `v` is a `vector<T, Allocator>` where `T`
|
| 11 |
-
is some type other than `bool`, then it obeys the identity
|
| 12 |
-
`&v[n] == &v[0] + n` for all `0 <= n < v.size()`.
|
| 13 |
|
| 14 |
A `vector` satisfies all of the requirements of a container and of a
|
| 15 |
reversible container (given in two tables in
|
| 16 |
[[container.requirements]]), of a sequence container, including most of
|
| 17 |
-
the optional sequence container requirements ([[sequence.reqmts]]),
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
| 24 |
|
| 25 |
``` cpp
|
| 26 |
namespace std {
|
| 27 |
template <class T, class Allocator = allocator<T>>
|
| 28 |
class vector {
|
| 29 |
public:
|
| 30 |
// types:
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
|
| 44 |
-
// [vector.cons], construct/copy/destroy
|
| 45 |
-
vector() : vector(Allocator()) { }
|
| 46 |
-
explicit vector(const Allocator&);
|
| 47 |
explicit vector(size_type n, const Allocator& = Allocator());
|
| 48 |
vector(size_type n, const T& value, const Allocator& = Allocator());
|
| 49 |
template <class InputIterator>
|
| 50 |
-
vector(InputIterator first, InputIterator last,
|
| 51 |
-
const Allocator& = Allocator());
|
| 52 |
vector(const vector& x);
|
| 53 |
-
vector(vector&&);
|
| 54 |
vector(const vector&, const Allocator&);
|
| 55 |
vector(vector&&, const Allocator&);
|
| 56 |
vector(initializer_list<T>, const Allocator& = Allocator());
|
| 57 |
~vector();
|
| 58 |
vector& operator=(const vector& x);
|
| 59 |
-
vector& operator=(vector&& x)
|
|
|
|
|
|
|
| 60 |
vector& operator=(initializer_list<T>);
|
| 61 |
template <class InputIterator>
|
| 62 |
void assign(InputIterator first, InputIterator last);
|
| 63 |
void assign(size_type n, const T& u);
|
| 64 |
void assign(initializer_list<T>);
|
|
@@ -77,17 +75,17 @@ namespace std {
|
|
| 77 |
const_iterator cbegin() const noexcept;
|
| 78 |
const_iterator cend() const noexcept;
|
| 79 |
const_reverse_iterator crbegin() const noexcept;
|
| 80 |
const_reverse_iterator crend() const noexcept;
|
| 81 |
|
| 82 |
-
// [vector.capacity], capacity
|
|
|
|
| 83 |
size_type size() const noexcept;
|
| 84 |
size_type max_size() const noexcept;
|
|
|
|
| 85 |
void resize(size_type sz);
|
| 86 |
void resize(size_type sz, const T& c);
|
| 87 |
-
size_type capacity() const noexcept;
|
| 88 |
-
bool empty() const noexcept;
|
| 89 |
void reserve(size_type n);
|
| 90 |
void shrink_to_fit();
|
| 91 |
|
| 92 |
// element access:
|
| 93 |
reference operator[](size_type n);
|
|
@@ -101,30 +99,36 @@ namespace std {
|
|
| 101 |
|
| 102 |
// [vector.data], data access
|
| 103 |
T* data() noexcept;
|
| 104 |
const T* data() const noexcept;
|
| 105 |
|
| 106 |
-
// [vector.modifiers], modifiers
|
| 107 |
-
template <class... Args>
|
| 108 |
void push_back(const T& x);
|
| 109 |
void push_back(T&& x);
|
| 110 |
void pop_back();
|
| 111 |
|
| 112 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 113 |
iterator insert(const_iterator position, const T& x);
|
| 114 |
iterator insert(const_iterator position, T&& x);
|
| 115 |
iterator insert(const_iterator position, size_type n, const T& x);
|
| 116 |
template <class InputIterator>
|
| 117 |
-
|
| 118 |
-
InputIterator first, InputIterator last);
|
| 119 |
iterator insert(const_iterator position, initializer_list<T> il);
|
| 120 |
iterator erase(const_iterator position);
|
| 121 |
iterator erase(const_iterator first, const_iterator last);
|
| 122 |
-
void swap(vector&)
|
|
|
|
|
|
|
| 123 |
void clear() noexcept;
|
| 124 |
};
|
| 125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
template <class T, class Allocator>
|
| 127 |
bool operator==(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 128 |
template <class T, class Allocator>
|
| 129 |
bool operator< (const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 130 |
template <class T, class Allocator>
|
|
@@ -134,16 +138,22 @@ namespace std {
|
|
| 134 |
template <class T, class Allocator>
|
| 135 |
bool operator>=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 136 |
template <class T, class Allocator>
|
| 137 |
bool operator<=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 138 |
|
| 139 |
-
// [vector.special], specialized algorithms
|
| 140 |
template <class T, class Allocator>
|
| 141 |
-
void swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
|
|
|
|
| 142 |
}
|
| 143 |
```
|
| 144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
#### `vector` constructors, copy, and assignment <a id="vector.cons">[[vector.cons]]</a>
|
| 146 |
|
| 147 |
``` cpp
|
| 148 |
explicit vector(const Allocator&);
|
| 149 |
```
|
|
@@ -184,13 +194,13 @@ template <class InputIterator>
|
|
| 184 |
*Effects:* Constructs a `vector` equal to the range \[`first`, `last`),
|
| 185 |
using the specified allocator.
|
| 186 |
|
| 187 |
*Complexity:* Makes only N calls to the copy constructor of `T` (where N
|
| 188 |
is the distance between `first` and `last`) and no reallocations if
|
| 189 |
-
iterators first and last are of forward, bidirectional, or random
|
| 190 |
-
categories. It makes order `N` calls to the copy constructor of
|
| 191 |
-
order log
|
| 192 |
|
| 193 |
#### `vector` capacity <a id="vector.capacity">[[vector.capacity]]</a>
|
| 194 |
|
| 195 |
``` cpp
|
| 196 |
size_type capacity() const noexcept;
|
|
@@ -229,20 +239,30 @@ vector greater than the value of `capacity()`.
|
|
| 229 |
void shrink_to_fit();
|
| 230 |
```
|
| 231 |
|
| 232 |
*Requires:* `T` shall be `MoveInsertable` into `*this`.
|
| 233 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
*Complexity:* Linear in the size of the sequence.
|
| 235 |
|
| 236 |
-
*Remarks:*
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
other than by the move constructor of a non-`CopyInsertable` `T` there
|
| 240 |
-
are no effects.
|
| 241 |
|
| 242 |
``` cpp
|
| 243 |
-
void swap(vector& x)
|
|
|
|
|
|
|
| 244 |
```
|
| 245 |
|
| 246 |
*Effects:* Exchanges the contents and `capacity()` of `*this` with that
|
| 247 |
of `x`.
|
| 248 |
|
|
@@ -250,13 +270,13 @@ of `x`.
|
|
| 250 |
|
| 251 |
``` cpp
|
| 252 |
void resize(size_type sz);
|
| 253 |
```
|
| 254 |
|
| 255 |
-
*Effects:* If `sz <
|
| 256 |
-
|
| 257 |
-
|
| 258 |
|
| 259 |
*Requires:* `T` shall be `MoveInsertable` and `DefaultInsertable` into
|
| 260 |
`*this`.
|
| 261 |
|
| 262 |
*Remarks:* If an exception is thrown other than by the move constructor
|
|
@@ -264,13 +284,13 @@ of a non-`CopyInsertable` `T` there are no effects.
|
|
| 264 |
|
| 265 |
``` cpp
|
| 266 |
void resize(size_type sz, const T& c);
|
| 267 |
```
|
| 268 |
|
| 269 |
-
*Effects:* If `sz <
|
| 270 |
-
|
| 271 |
-
|
| 272 |
|
| 273 |
*Requires:* `T` shall be `CopyInsertable` into `*this`.
|
| 274 |
|
| 275 |
*Remarks:* If an exception is thrown there are no effects.
|
| 276 |
|
|
@@ -280,11 +300,11 @@ void resize(size_type sz, const T& c);
|
|
| 280 |
T* data() noexcept;
|
| 281 |
const T* data() const noexcept;
|
| 282 |
```
|
| 283 |
|
| 284 |
*Returns:* A pointer such that \[`data()`, `data() + size()`) is a valid
|
| 285 |
-
range. For a non-empty vector, `data()` `==` `
|
| 286 |
|
| 287 |
*Complexity:* Constant time.
|
| 288 |
|
| 289 |
#### `vector` modifiers <a id="vector.modifiers">[[vector.modifiers]]</a>
|
| 290 |
|
|
@@ -294,55 +314,54 @@ iterator insert(const_iterator position, T&& x);
|
|
| 294 |
iterator insert(const_iterator position, size_type n, const T& x);
|
| 295 |
template <class InputIterator>
|
| 296 |
iterator insert(const_iterator position, InputIterator first, InputIterator last);
|
| 297 |
iterator insert(const_iterator position, initializer_list<T>);
|
| 298 |
|
| 299 |
-
template <class... Args>
|
| 300 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 301 |
void push_back(const T& x);
|
| 302 |
void push_back(T&& x);
|
| 303 |
```
|
| 304 |
|
| 305 |
*Remarks:* Causes reallocation if the new size is greater than the old
|
| 306 |
-
capacity.
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
|
|
|
|
|
|
| 315 |
|
| 316 |
*Complexity:* The complexity is linear in the number of elements
|
| 317 |
inserted plus the distance to the end of the vector.
|
| 318 |
|
| 319 |
``` cpp
|
| 320 |
iterator erase(const_iterator position);
|
| 321 |
iterator erase(const_iterator first, const_iterator last);
|
|
|
|
| 322 |
```
|
| 323 |
|
| 324 |
*Effects:* Invalidates iterators and references at or after the point of
|
| 325 |
the erase.
|
| 326 |
|
| 327 |
*Complexity:* The destructor of `T` is called the number of times equal
|
| 328 |
-
to the number of the elements erased, but the
|
| 329 |
-
|
| 330 |
-
|
| 331 |
|
| 332 |
-
*Throws:* Nothing unless an exception is thrown by the
|
| 333 |
-
|
| 334 |
-
`T`.
|
| 335 |
|
| 336 |
#### `vector` specialized algorithms <a id="vector.special">[[vector.special]]</a>
|
| 337 |
|
| 338 |
``` cpp
|
| 339 |
template <class T, class Allocator>
|
| 340 |
-
void swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
|
|
|
|
| 341 |
```
|
| 342 |
|
| 343 |
-
*Effects:*
|
| 344 |
-
|
| 345 |
-
``` cpp
|
| 346 |
-
x.swap(y);
|
| 347 |
-
```
|
| 348 |
|
|
|
|
| 1 |
### Class template `vector` <a id="vector">[[vector]]</a>
|
| 2 |
|
| 3 |
#### Class template `vector` overview <a id="vector.overview">[[vector.overview]]</a>
|
| 4 |
|
| 5 |
+
A `vector` is a sequence container that supports (amortized) constant
|
| 6 |
+
time insert and erase operations at the end; insert and erase in the
|
| 7 |
+
middle take linear time. Storage management is handled automatically,
|
| 8 |
+
though hints can be given to improve efficiency.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
A `vector` satisfies all of the requirements of a container and of a
|
| 11 |
reversible container (given in two tables in
|
| 12 |
[[container.requirements]]), of a sequence container, including most of
|
| 13 |
+
the optional sequence container requirements ([[sequence.reqmts]]), of
|
| 14 |
+
an allocator-aware container (Table [[tab:containers.allocatoraware]]),
|
| 15 |
+
and, for an element type other than `bool`, of a contiguous container (
|
| 16 |
+
[[container.requirements.general]]). The exceptions are the
|
| 17 |
+
`push_front`, `pop_front`, and `emplace_front` member functions, which
|
| 18 |
+
are not provided. Descriptions are provided here only for operations on
|
| 19 |
+
`vector` that are not described in one of these tables or for operations
|
| 20 |
+
where there is additional semantic information.
|
| 21 |
|
| 22 |
``` cpp
|
| 23 |
namespace std {
|
| 24 |
template <class T, class Allocator = allocator<T>>
|
| 25 |
class vector {
|
| 26 |
public:
|
| 27 |
// types:
|
| 28 |
+
using value_type = T;
|
| 29 |
+
using allocator_type = Allocator;
|
| 30 |
+
using pointer = typename allocator_traits<Allocator>::pointer;
|
| 31 |
+
using const_pointer = typename allocator_traits<Allocator>::const_pointer;
|
| 32 |
+
using reference = value_type&;
|
| 33 |
+
using const_reference = const value_type&;
|
| 34 |
+
using size_type = implementation-defined; // see [container.requirements]
|
| 35 |
+
using difference_type = implementation-defined; // see [container.requirements]
|
| 36 |
+
using iterator = implementation-defined // type of vector::iterator; // see [container.requirements]
|
| 37 |
+
using const_iterator = implementation-defined // type of vector::const_iterator; // see [container.requirements]
|
| 38 |
+
using reverse_iterator = std::reverse_iterator<iterator>;
|
| 39 |
+
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
| 40 |
|
| 41 |
+
// [vector.cons], construct/copy/destroy
|
| 42 |
+
vector() noexcept(noexcept(Allocator())) : vector(Allocator()) { }
|
| 43 |
+
explicit vector(const Allocator&) noexcept;
|
| 44 |
explicit vector(size_type n, const Allocator& = Allocator());
|
| 45 |
vector(size_type n, const T& value, const Allocator& = Allocator());
|
| 46 |
template <class InputIterator>
|
| 47 |
+
vector(InputIterator first, InputIterator last, const Allocator& = Allocator());
|
|
|
|
| 48 |
vector(const vector& x);
|
| 49 |
+
vector(vector&&) noexcept;
|
| 50 |
vector(const vector&, const Allocator&);
|
| 51 |
vector(vector&&, const Allocator&);
|
| 52 |
vector(initializer_list<T>, const Allocator& = Allocator());
|
| 53 |
~vector();
|
| 54 |
vector& operator=(const vector& x);
|
| 55 |
+
vector& operator=(vector&& x)
|
| 56 |
+
noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
|
| 57 |
+
allocator_traits<Allocator>::is_always_equal::value);
|
| 58 |
vector& operator=(initializer_list<T>);
|
| 59 |
template <class InputIterator>
|
| 60 |
void assign(InputIterator first, InputIterator last);
|
| 61 |
void assign(size_type n, const T& u);
|
| 62 |
void assign(initializer_list<T>);
|
|
|
|
| 75 |
const_iterator cbegin() const noexcept;
|
| 76 |
const_iterator cend() const noexcept;
|
| 77 |
const_reverse_iterator crbegin() const noexcept;
|
| 78 |
const_reverse_iterator crend() const noexcept;
|
| 79 |
|
| 80 |
+
// [vector.capacity], capacity
|
| 81 |
+
bool empty() const noexcept;
|
| 82 |
size_type size() const noexcept;
|
| 83 |
size_type max_size() const noexcept;
|
| 84 |
+
size_type capacity() const noexcept;
|
| 85 |
void resize(size_type sz);
|
| 86 |
void resize(size_type sz, const T& c);
|
|
|
|
|
|
|
| 87 |
void reserve(size_type n);
|
| 88 |
void shrink_to_fit();
|
| 89 |
|
| 90 |
// element access:
|
| 91 |
reference operator[](size_type n);
|
|
|
|
| 99 |
|
| 100 |
// [vector.data], data access
|
| 101 |
T* data() noexcept;
|
| 102 |
const T* data() const noexcept;
|
| 103 |
|
| 104 |
+
// [vector.modifiers], modifiers
|
| 105 |
+
template <class... Args> reference emplace_back(Args&&... args);
|
| 106 |
void push_back(const T& x);
|
| 107 |
void push_back(T&& x);
|
| 108 |
void pop_back();
|
| 109 |
|
| 110 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 111 |
iterator insert(const_iterator position, const T& x);
|
| 112 |
iterator insert(const_iterator position, T&& x);
|
| 113 |
iterator insert(const_iterator position, size_type n, const T& x);
|
| 114 |
template <class InputIterator>
|
| 115 |
+
iterator insert(const_iterator position, InputIterator first, InputIterator last);
|
|
|
|
| 116 |
iterator insert(const_iterator position, initializer_list<T> il);
|
| 117 |
iterator erase(const_iterator position);
|
| 118 |
iterator erase(const_iterator first, const_iterator last);
|
| 119 |
+
void swap(vector&)
|
| 120 |
+
noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
|
| 121 |
+
allocator_traits<Allocator>::is_always_equal::value);
|
| 122 |
void clear() noexcept;
|
| 123 |
};
|
| 124 |
|
| 125 |
+
template<class InputIterator,
|
| 126 |
+
class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
|
| 127 |
+
vector(InputIterator, InputIterator, Allocator = Allocator())
|
| 128 |
+
-> vector<typename iterator_traits<InputIterator>::value_type, Allocator>;
|
| 129 |
+
|
| 130 |
template <class T, class Allocator>
|
| 131 |
bool operator==(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 132 |
template <class T, class Allocator>
|
| 133 |
bool operator< (const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 134 |
template <class T, class Allocator>
|
|
|
|
| 138 |
template <class T, class Allocator>
|
| 139 |
bool operator>=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 140 |
template <class T, class Allocator>
|
| 141 |
bool operator<=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 142 |
|
| 143 |
+
// [vector.special], specialized algorithms
|
| 144 |
template <class T, class Allocator>
|
| 145 |
+
void swap(vector<T, Allocator>& x, vector<T, Allocator>& y)
|
| 146 |
+
noexcept(noexcept(x.swap(y)));
|
| 147 |
}
|
| 148 |
```
|
| 149 |
|
| 150 |
+
An incomplete type `T` may be used when instantiating `vector` if the
|
| 151 |
+
allocator satisfies the allocator completeness requirements (
|
| 152 |
+
[[allocator.requirements.completeness]]). `T` shall be complete before
|
| 153 |
+
any member of the resulting specialization of `vector` is referenced.
|
| 154 |
+
|
| 155 |
#### `vector` constructors, copy, and assignment <a id="vector.cons">[[vector.cons]]</a>
|
| 156 |
|
| 157 |
``` cpp
|
| 158 |
explicit vector(const Allocator&);
|
| 159 |
```
|
|
|
|
| 194 |
*Effects:* Constructs a `vector` equal to the range \[`first`, `last`),
|
| 195 |
using the specified allocator.
|
| 196 |
|
| 197 |
*Complexity:* Makes only N calls to the copy constructor of `T` (where N
|
| 198 |
is the distance between `first` and `last`) and no reallocations if
|
| 199 |
+
iterators `first` and `last` are of forward, bidirectional, or random
|
| 200 |
+
access categories. It makes order `N` calls to the copy constructor of
|
| 201 |
+
`T` and order log N reallocations if they are just input iterators.
|
| 202 |
|
| 203 |
#### `vector` capacity <a id="vector.capacity">[[vector.capacity]]</a>
|
| 204 |
|
| 205 |
``` cpp
|
| 206 |
size_type capacity() const noexcept;
|
|
|
|
| 239 |
void shrink_to_fit();
|
| 240 |
```
|
| 241 |
|
| 242 |
*Requires:* `T` shall be `MoveInsertable` into `*this`.
|
| 243 |
|
| 244 |
+
*Effects:* `shrink_to_fit` is a non-binding request to reduce
|
| 245 |
+
`capacity()` to `size()`.
|
| 246 |
+
|
| 247 |
+
[*Note 1*: The request is non-binding to allow latitude for
|
| 248 |
+
implementation-specific optimizations. — *end note*]
|
| 249 |
+
|
| 250 |
+
It does not increase `capacity()`, but may reduce `capacity()` by
|
| 251 |
+
causing reallocation. If an exception is thrown other than by the move
|
| 252 |
+
constructor of a non-`CopyInsertable` `T` there are no effects.
|
| 253 |
+
|
| 254 |
*Complexity:* Linear in the size of the sequence.
|
| 255 |
|
| 256 |
+
*Remarks:* Reallocation invalidates all the references, pointers, and
|
| 257 |
+
iterators referring to the elements in the sequence as well as the
|
| 258 |
+
past-the-end iterator. If no reallocation happens, they remain valid.
|
|
|
|
|
|
|
| 259 |
|
| 260 |
``` cpp
|
| 261 |
+
void swap(vector& x)
|
| 262 |
+
noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
|
| 263 |
+
allocator_traits<Allocator>::is_always_equal::value);
|
| 264 |
```
|
| 265 |
|
| 266 |
*Effects:* Exchanges the contents and `capacity()` of `*this` with that
|
| 267 |
of `x`.
|
| 268 |
|
|
|
|
| 270 |
|
| 271 |
``` cpp
|
| 272 |
void resize(size_type sz);
|
| 273 |
```
|
| 274 |
|
| 275 |
+
*Effects:* If `sz < size()`, erases the last `size() - sz` elements from
|
| 276 |
+
the sequence. Otherwise, appends `sz - size()` default-inserted elements
|
| 277 |
+
to the sequence.
|
| 278 |
|
| 279 |
*Requires:* `T` shall be `MoveInsertable` and `DefaultInsertable` into
|
| 280 |
`*this`.
|
| 281 |
|
| 282 |
*Remarks:* If an exception is thrown other than by the move constructor
|
|
|
|
| 284 |
|
| 285 |
``` cpp
|
| 286 |
void resize(size_type sz, const T& c);
|
| 287 |
```
|
| 288 |
|
| 289 |
+
*Effects:* If `sz < size()`, erases the last `size() - sz` elements from
|
| 290 |
+
the sequence. Otherwise, appends `sz - size()` copies of `c` to the
|
| 291 |
+
sequence.
|
| 292 |
|
| 293 |
*Requires:* `T` shall be `CopyInsertable` into `*this`.
|
| 294 |
|
| 295 |
*Remarks:* If an exception is thrown there are no effects.
|
| 296 |
|
|
|
|
| 300 |
T* data() noexcept;
|
| 301 |
const T* data() const noexcept;
|
| 302 |
```
|
| 303 |
|
| 304 |
*Returns:* A pointer such that \[`data()`, `data() + size()`) is a valid
|
| 305 |
+
range. For a non-empty vector, `data()` `==` `addressof(front())`.
|
| 306 |
|
| 307 |
*Complexity:* Constant time.
|
| 308 |
|
| 309 |
#### `vector` modifiers <a id="vector.modifiers">[[vector.modifiers]]</a>
|
| 310 |
|
|
|
|
| 314 |
iterator insert(const_iterator position, size_type n, const T& x);
|
| 315 |
template <class InputIterator>
|
| 316 |
iterator insert(const_iterator position, InputIterator first, InputIterator last);
|
| 317 |
iterator insert(const_iterator position, initializer_list<T>);
|
| 318 |
|
| 319 |
+
template <class... Args> reference emplace_back(Args&&... args);
|
| 320 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 321 |
void push_back(const T& x);
|
| 322 |
void push_back(T&& x);
|
| 323 |
```
|
| 324 |
|
| 325 |
*Remarks:* Causes reallocation if the new size is greater than the old
|
| 326 |
+
capacity. Reallocation invalidates all the references, pointers, and
|
| 327 |
+
iterators referring to the elements in the sequence. If no reallocation
|
| 328 |
+
happens, all the iterators and references before the insertion point
|
| 329 |
+
remain valid. If an exception is thrown other than by the copy
|
| 330 |
+
constructor, move constructor, assignment operator, or move assignment
|
| 331 |
+
operator of `T` or by any `InputIterator` operation there are no
|
| 332 |
+
effects. If an exception is thrown while inserting a single element at
|
| 333 |
+
the end and `T` is `CopyInsertable` or
|
| 334 |
+
`is_nothrow_move_constructible_v<T>` is `true`, there are no effects.
|
| 335 |
+
Otherwise, if an exception is thrown by the move constructor of a
|
| 336 |
+
non-`CopyInsertable` `T`, the effects are unspecified.
|
| 337 |
|
| 338 |
*Complexity:* The complexity is linear in the number of elements
|
| 339 |
inserted plus the distance to the end of the vector.
|
| 340 |
|
| 341 |
``` cpp
|
| 342 |
iterator erase(const_iterator position);
|
| 343 |
iterator erase(const_iterator first, const_iterator last);
|
| 344 |
+
void pop_back();
|
| 345 |
```
|
| 346 |
|
| 347 |
*Effects:* Invalidates iterators and references at or after the point of
|
| 348 |
the erase.
|
| 349 |
|
| 350 |
*Complexity:* The destructor of `T` is called the number of times equal
|
| 351 |
+
to the number of the elements erased, but the assignment operator of `T`
|
| 352 |
+
is called the number of times equal to the number of elements in the
|
| 353 |
+
vector after the erased elements.
|
| 354 |
|
| 355 |
+
*Throws:* Nothing unless an exception is thrown by the assignment
|
| 356 |
+
operator or move assignment operator of `T`.
|
|
|
|
| 357 |
|
| 358 |
#### `vector` specialized algorithms <a id="vector.special">[[vector.special]]</a>
|
| 359 |
|
| 360 |
``` cpp
|
| 361 |
template <class T, class Allocator>
|
| 362 |
+
void swap(vector<T, Allocator>& x, vector<T, Allocator>& y)
|
| 363 |
+
noexcept(noexcept(x.swap(y)));
|
| 364 |
```
|
| 365 |
|
| 366 |
+
*Effects:* As if by `x.swap(y)`.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
|