- tmp/tmp60kp38mx/{from.md → to.md} +428 -356
tmp/tmp60kp38mx/{from.md → to.md}
RENAMED
|
@@ -1,23 +1,20 @@
|
|
| 1 |
## Sequence containers <a id="sequences">[[sequences]]</a>
|
| 2 |
|
| 3 |
### In general <a id="sequences.general">[[sequences.general]]</a>
|
| 4 |
|
| 5 |
The headers `<array>`, `<deque>`, `<forward_list>`, `<list>`, and
|
| 6 |
-
`<vector>` define
|
| 7 |
sequence containers.
|
| 8 |
|
| 9 |
-
|
| 10 |
-
[[container.adaptors]]) that also meet the requirements for sequence
|
| 11 |
-
containers.
|
| 12 |
-
|
| 13 |
-
\synopsis{Header \texttt{\<array\>} synopsis}
|
| 14 |
|
| 15 |
``` cpp
|
| 16 |
#include <initializer_list>
|
| 17 |
|
| 18 |
namespace std {
|
|
|
|
| 19 |
template <class T, size_t N> struct array;
|
| 20 |
template <class T, size_t N>
|
| 21 |
bool operator==(const array<T, N>& x, const array<T, N>& y);
|
| 22 |
template <class T, size_t N>
|
| 23 |
bool operator!=(const array<T, N>& x, const array<T, N>& y);
|
|
@@ -42,19 +39,22 @@ namespace std {
|
|
| 42 |
constexpr T& get(array<T, N>&) noexcept;
|
| 43 |
template <size_t I, class T, size_t N>
|
| 44 |
constexpr T&& get(array<T, N>&&) noexcept;
|
| 45 |
template <size_t I, class T, size_t N>
|
| 46 |
constexpr const T& get(const array<T, N>&) noexcept;
|
|
|
|
|
|
|
| 47 |
}
|
| 48 |
```
|
| 49 |
|
| 50 |
-
|
| 51 |
|
| 52 |
``` cpp
|
| 53 |
#include <initializer_list>
|
| 54 |
|
| 55 |
namespace std {
|
|
|
|
| 56 |
template <class T, class Allocator = allocator<T>> class deque;
|
| 57 |
template <class T, class Allocator>
|
| 58 |
bool operator==(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 59 |
template <class T, class Allocator>
|
| 60 |
bool operator< (const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
|
@@ -65,20 +65,27 @@ namespace std {
|
|
| 65 |
template <class T, class Allocator>
|
| 66 |
bool operator>=(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 67 |
template <class T, class Allocator>
|
| 68 |
bool operator<=(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 69 |
template <class T, class Allocator>
|
| 70 |
-
void swap(deque<T,Allocator>& x, deque<T,Allocator>& y)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
}
|
| 72 |
```
|
| 73 |
|
| 74 |
-
|
| 75 |
|
| 76 |
``` cpp
|
| 77 |
#include <initializer_list>
|
| 78 |
|
| 79 |
namespace std {
|
|
|
|
| 80 |
template <class T, class Allocator = allocator<T>> class forward_list;
|
| 81 |
template <class T, class Allocator>
|
| 82 |
bool operator==(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 83 |
template <class T, class Allocator>
|
| 84 |
bool operator< (const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
|
@@ -89,20 +96,27 @@ namespace std {
|
|
| 89 |
template <class T, class Allocator>
|
| 90 |
bool operator>=(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 91 |
template <class T, class Allocator>
|
| 92 |
bool operator<=(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 93 |
template <class T, class Allocator>
|
| 94 |
-
void swap(forward_list<T,Allocator>& x, forward_list<T,Allocator>& y)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
}
|
| 96 |
```
|
| 97 |
|
| 98 |
-
|
| 99 |
|
| 100 |
``` cpp
|
| 101 |
#include <initializer_list>
|
| 102 |
|
| 103 |
namespace std {
|
|
|
|
| 104 |
template <class T, class Allocator = allocator<T>> class list;
|
| 105 |
template <class T, class Allocator>
|
| 106 |
bool operator==(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 107 |
template <class T, class Allocator>
|
| 108 |
bool operator< (const list<T, Allocator>& x, const list<T, Allocator>& y);
|
|
@@ -113,20 +127,27 @@ namespace std {
|
|
| 113 |
template <class T, class Allocator>
|
| 114 |
bool operator>=(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 115 |
template <class T, class Allocator>
|
| 116 |
bool operator<=(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 117 |
template <class T, class Allocator>
|
| 118 |
-
void swap(list<T,Allocator>& x, list<T,Allocator>& y)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
}
|
| 120 |
```
|
| 121 |
|
| 122 |
-
|
| 123 |
|
| 124 |
``` cpp
|
| 125 |
#include <initializer_list>
|
| 126 |
|
| 127 |
namespace std {
|
|
|
|
| 128 |
template <class T, class Allocator = allocator<T>> class vector;
|
| 129 |
template <class T, class Allocator>
|
| 130 |
bool operator==(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 131 |
template <class T, class Allocator>
|
| 132 |
bool operator< (const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
|
@@ -137,40 +158,39 @@ namespace std {
|
|
| 137 |
template <class T, class Allocator>
|
| 138 |
bool operator>=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 139 |
template <class T, class Allocator>
|
| 140 |
bool operator<=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 141 |
template <class T, class Allocator>
|
| 142 |
-
void swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
|
|
|
|
| 143 |
|
|
|
|
| 144 |
template <class Allocator> class vector<bool, Allocator>;
|
| 145 |
|
| 146 |
// hash support
|
| 147 |
template <class T> struct hash;
|
| 148 |
template <class Allocator> struct hash<vector<bool, Allocator>>;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
}
|
| 150 |
```
|
| 151 |
|
| 152 |
### Class template `array` <a id="array">[[array]]</a>
|
| 153 |
|
| 154 |
#### Class template `array` overview <a id="array.overview">[[array.overview]]</a>
|
| 155 |
|
| 156 |
The header `<array>` defines a class template for storing fixed-size
|
| 157 |
-
sequences of objects. An `array`
|
| 158 |
-
instance of `array<T, N>` stores
|
| 159 |
-
`size() == N` is an invariant.
|
| 160 |
-
contiguously, meaning that if `a` is an `array<T, N>` then it obeys the
|
| 161 |
-
identity `&a[n] == &a[0] + n` for all `0 <= n < N`.
|
| 162 |
|
| 163 |
-
An `array` is an aggregate ([[dcl.init.aggr]]) that can be
|
| 164 |
-
with
|
| 165 |
-
|
| 166 |
-
``` cpp
|
| 167 |
-
array<T, N> a = { initializer-list };
|
| 168 |
-
```
|
| 169 |
-
|
| 170 |
-
where *initializer-list* is a comma-separated list of up to `N` elements
|
| 171 |
-
whose types are convertible to `T`.
|
| 172 |
|
| 173 |
An `array` satisfies all of the requirements of a container and of a
|
| 174 |
reversible container ([[container.requirements]]), except that a
|
| 175 |
default constructed `array` object is not empty and that `swap` does not
|
| 176 |
have constant complexity. An `array` satisfies some of the requirements
|
|
@@ -182,70 +202,67 @@ semantic information.
|
|
| 182 |
``` cpp
|
| 183 |
namespace std {
|
| 184 |
template <class T, size_t N>
|
| 185 |
struct array {
|
| 186 |
// types:
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
T elems[N]; // exposition only
|
| 200 |
|
| 201 |
// no explicit construct/copy/destroy for aggregate type
|
| 202 |
|
| 203 |
void fill(const T& u);
|
| 204 |
-
void swap(array&) noexcept(
|
| 205 |
|
| 206 |
// iterators:
|
| 207 |
-
iterator begin() noexcept;
|
| 208 |
-
const_iterator begin() const noexcept;
|
| 209 |
-
iterator end() noexcept;
|
| 210 |
-
const_iterator end() const noexcept;
|
| 211 |
|
| 212 |
-
reverse_iterator rbegin() noexcept;
|
| 213 |
-
const_reverse_iterator rbegin() const noexcept;
|
| 214 |
-
reverse_iterator rend() noexcept;
|
| 215 |
-
const_reverse_iterator rend() const noexcept;
|
| 216 |
|
| 217 |
-
const_iterator cbegin() const noexcept;
|
| 218 |
-
const_iterator cend() const noexcept;
|
| 219 |
-
const_reverse_iterator crbegin() const noexcept;
|
| 220 |
-
const_reverse_iterator crend() const noexcept;
|
| 221 |
|
| 222 |
// capacity:
|
|
|
|
| 223 |
constexpr size_type size() const noexcept;
|
| 224 |
constexpr size_type max_size() const noexcept;
|
| 225 |
-
constexpr bool empty() const noexcept;
|
| 226 |
|
| 227 |
// element access:
|
| 228 |
-
reference
|
| 229 |
constexpr const_reference operator[](size_type n) const;
|
| 230 |
-
reference
|
| 231 |
constexpr const_reference at(size_type n) const;
|
| 232 |
-
reference
|
| 233 |
constexpr const_reference front() const;
|
| 234 |
-
reference
|
| 235 |
constexpr const_reference back() const;
|
| 236 |
|
| 237 |
-
T * data() noexcept;
|
| 238 |
-
const T * data() const noexcept;
|
| 239 |
};
|
|
|
|
|
|
|
|
|
|
| 240 |
}
|
| 241 |
```
|
| 242 |
|
| 243 |
-
The member variable `elems` is shown for exposition only, to emphasize
|
| 244 |
-
that `array` is a class aggregate. The name `elems` is not part of
|
| 245 |
-
`array`’s interface.
|
| 246 |
-
|
| 247 |
#### `array` constructors, copy, and assignment <a id="array.cons">[[array.cons]]</a>
|
| 248 |
|
| 249 |
The conditions for an aggregate ([[dcl.init.aggr]]) shall be met. Class
|
| 250 |
`array` relies on the implicitly-declared special member functions (
|
| 251 |
[[class.ctor]], [[class.dtor]], and [[class.copy]]) to conform to the
|
|
@@ -253,63 +270,70 @@ container requirements table in [[container.requirements]]. In addition
|
|
| 253 |
to the requirements specified in the container requirements table, the
|
| 254 |
implicit move constructor and move assignment operator for `array`
|
| 255 |
require that `T` be `MoveConstructible` or `MoveAssignable`,
|
| 256 |
respectively.
|
| 257 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
#### `array` specialized algorithms <a id="array.special">[[array.special]]</a>
|
| 259 |
|
| 260 |
``` cpp
|
| 261 |
-
template <class T, size_t N>
|
|
|
|
| 262 |
```
|
| 263 |
|
| 264 |
-
*
|
|
|
|
| 265 |
|
| 266 |
-
``
|
| 267 |
-
x.swap(y);
|
| 268 |
-
```
|
| 269 |
|
| 270 |
*Complexity:* Linear in `N`.
|
| 271 |
|
| 272 |
#### `array::size` <a id="array.size">[[array.size]]</a>
|
| 273 |
|
| 274 |
``` cpp
|
| 275 |
template <class T, size_t N> constexpr size_type array<T, N>::size() const noexcept;
|
| 276 |
```
|
| 277 |
|
| 278 |
-
*Returns:* `N`
|
| 279 |
|
| 280 |
#### `array::data` <a id="array.data">[[array.data]]</a>
|
| 281 |
|
| 282 |
``` cpp
|
| 283 |
-
T* data() noexcept;
|
| 284 |
-
const T* data() const noexcept;
|
| 285 |
```
|
| 286 |
|
| 287 |
-
*Returns:* `
|
|
|
|
| 288 |
|
| 289 |
#### `array::fill` <a id="array.fill">[[array.fill]]</a>
|
| 290 |
|
| 291 |
``` cpp
|
| 292 |
void fill(const T& u);
|
| 293 |
```
|
| 294 |
|
| 295 |
-
*Effects:* `fill_n(begin(), N, u)`
|
| 296 |
|
| 297 |
#### `array::swap` <a id="array.swap">[[array.swap]]</a>
|
| 298 |
|
| 299 |
``` cpp
|
| 300 |
-
void swap(array& y) noexcept(
|
| 301 |
```
|
| 302 |
|
| 303 |
-
*Effects:* `swap_ranges(begin(), end(), y.begin())`
|
| 304 |
|
| 305 |
-
*
|
| 306 |
-
exception
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
takes linear time, may exit via an exception, and does not cause
|
| 310 |
-
iterators to become associated with the other container.
|
| 311 |
|
| 312 |
#### Zero sized arrays <a id="array.zero">[[array.zero]]</a>
|
| 313 |
|
| 314 |
`array` shall provide support for the special case `N == 0`.
|
| 315 |
|
|
@@ -317,19 +341,18 @@ In the case that `N == 0`, `begin() == end() ==` unique value. The
|
|
| 317 |
return value of `data()` is unspecified.
|
| 318 |
|
| 319 |
The effect of calling `front()` or `back()` for a zero-sized array is
|
| 320 |
undefined.
|
| 321 |
|
| 322 |
-
Member function `swap()` shall have a
|
| 323 |
-
|
| 324 |
|
| 325 |
#### Tuple interface to class template `array` <a id="array.tuple">[[array.tuple]]</a>
|
| 326 |
|
| 327 |
``` cpp
|
| 328 |
template <class T, size_t N>
|
| 329 |
-
struct tuple_size<array<T, N>>
|
| 330 |
-
: integral_constant<size_t, N> { };
|
| 331 |
```
|
| 332 |
|
| 333 |
``` cpp
|
| 334 |
tuple_element<I, array<T, N>>::type
|
| 335 |
```
|
|
@@ -339,44 +362,33 @@ tuple_element<I, array<T, N> >::type
|
|
| 339 |
*Value:* The type T.
|
| 340 |
|
| 341 |
``` cpp
|
| 342 |
template <size_t I, class T, size_t N>
|
| 343 |
constexpr T& get(array<T, N>& a) noexcept;
|
| 344 |
-
```
|
| 345 |
-
|
| 346 |
-
*Requires:* `I < N`. The program is ill-formed if `I` is out of bounds.
|
| 347 |
-
|
| 348 |
-
*Returns:* A reference to the `I`th element of `a`, where indexing is
|
| 349 |
-
zero-based.
|
| 350 |
-
|
| 351 |
-
``` cpp
|
| 352 |
template <size_t I, class T, size_t N>
|
| 353 |
constexpr T&& get(array<T, N>&& a) noexcept;
|
| 354 |
-
```
|
| 355 |
-
|
| 356 |
-
*Effects:* Equivalent to `return std::move(get<I>(a));`
|
| 357 |
-
|
| 358 |
-
``` cpp
|
| 359 |
template <size_t I, class T, size_t N>
|
| 360 |
constexpr const T& get(const array<T, N>& a) noexcept;
|
|
|
|
|
|
|
| 361 |
```
|
| 362 |
|
| 363 |
*Requires:* `I < N`. The program is ill-formed if `I` is out of bounds.
|
| 364 |
|
| 365 |
-
*Returns:* A
|
| 366 |
-
|
| 367 |
|
| 368 |
### Class template `deque` <a id="deque">[[deque]]</a>
|
| 369 |
|
| 370 |
#### Class template `deque` overview <a id="deque.overview">[[deque.overview]]</a>
|
| 371 |
|
| 372 |
-
A `deque` is a sequence container that
|
| 373 |
-
|
| 374 |
insert and erase operations at the beginning or the end; insert and
|
| 375 |
erase in the middle take linear time. That is, a deque is especially
|
| 376 |
-
optimized for pushing and popping elements at the beginning and end.
|
| 377 |
-
|
| 378 |
|
| 379 |
A `deque` satisfies all of the requirements of a container, of a
|
| 380 |
reversible container (given in tables in [[container.requirements]]),
|
| 381 |
of a sequence container, including the optional sequence container
|
| 382 |
requirements ([[sequence.reqmts]]), and of an allocator-aware container
|
|
@@ -389,24 +401,24 @@ information.
|
|
| 389 |
namespace std {
|
| 390 |
template <class T, class Allocator = allocator<T>>
|
| 391 |
class deque {
|
| 392 |
public:
|
| 393 |
// types:
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
|
| 407 |
-
// [deque.cons], construct/copy/destroy
|
| 408 |
deque() : deque(Allocator()) { }
|
| 409 |
explicit deque(const Allocator&);
|
| 410 |
explicit deque(size_type n, const Allocator& = Allocator());
|
| 411 |
deque(size_type n, const T& value, const Allocator& = Allocator());
|
| 412 |
template <class InputIterator>
|
|
@@ -417,11 +429,12 @@ namespace std {
|
|
| 417 |
deque(deque&&, const Allocator&);
|
| 418 |
deque(initializer_list<T>, const Allocator& = Allocator());
|
| 419 |
|
| 420 |
~deque();
|
| 421 |
deque& operator=(const deque& x);
|
| 422 |
-
deque& operator=(deque&& x)
|
|
|
|
| 423 |
deque& operator=(initializer_list<T>);
|
| 424 |
template <class InputIterator>
|
| 425 |
void assign(InputIterator first, InputIterator last);
|
| 426 |
void assign(size_type n, const T& t);
|
| 427 |
void assign(initializer_list<T>);
|
|
@@ -440,17 +453,17 @@ namespace std {
|
|
| 440 |
const_iterator cbegin() const noexcept;
|
| 441 |
const_iterator cend() const noexcept;
|
| 442 |
const_reverse_iterator crbegin() const noexcept;
|
| 443 |
const_reverse_iterator crend() const noexcept;
|
| 444 |
|
| 445 |
-
// [deque.capacity], capacity
|
|
|
|
| 446 |
size_type size() const noexcept;
|
| 447 |
size_type max_size() const noexcept;
|
| 448 |
void resize(size_type sz);
|
| 449 |
void resize(size_type sz, const T& c);
|
| 450 |
void shrink_to_fit();
|
| 451 |
-
bool empty() const noexcept;
|
| 452 |
|
| 453 |
// element access:
|
| 454 |
reference operator[](size_type n);
|
| 455 |
const_reference operator[](size_type n) const;
|
| 456 |
reference at(size_type n);
|
|
@@ -458,13 +471,13 @@ namespace std {
|
|
| 458 |
reference front();
|
| 459 |
const_reference front() const;
|
| 460 |
reference back();
|
| 461 |
const_reference back() const;
|
| 462 |
|
| 463 |
-
// [deque.modifiers], modifiers
|
| 464 |
-
template <class... Args>
|
| 465 |
-
template <class... Args>
|
| 466 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 467 |
|
| 468 |
void push_front(const T& x);
|
| 469 |
void push_front(T&& x);
|
| 470 |
void push_back(const T& x);
|
|
@@ -480,14 +493,20 @@ namespace std {
|
|
| 480 |
void pop_front();
|
| 481 |
void pop_back();
|
| 482 |
|
| 483 |
iterator erase(const_iterator position);
|
| 484 |
iterator erase(const_iterator first, const_iterator last);
|
| 485 |
-
void swap(deque&)
|
|
|
|
| 486 |
void clear() noexcept;
|
| 487 |
};
|
| 488 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 489 |
template <class T, class Allocator>
|
| 490 |
bool operator==(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 491 |
template <class T, class Allocator>
|
| 492 |
bool operator< (const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 493 |
template <class T, class Allocator>
|
|
@@ -497,13 +516,14 @@ namespace std {
|
|
| 497 |
template <class T, class Allocator>
|
| 498 |
bool operator>=(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 499 |
template <class T, class Allocator>
|
| 500 |
bool operator<=(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 501 |
|
| 502 |
-
// specialized algorithms
|
| 503 |
template <class T, class Allocator>
|
| 504 |
-
void swap(deque<T,Allocator>& x, deque<T,Allocator>& y)
|
|
|
|
| 505 |
}
|
| 506 |
```
|
| 507 |
|
| 508 |
#### `deque` constructors, copy, and assignment <a id="deque.cons">[[deque.cons]]</a>
|
| 509 |
|
|
@@ -525,12 +545,11 @@ the specified allocator.
|
|
| 525 |
*Requires:* `T` shall be `DefaultInsertable` into `*this`.
|
| 526 |
|
| 527 |
*Complexity:* Linear in `n`.
|
| 528 |
|
| 529 |
``` cpp
|
| 530 |
-
deque(size_type n, const T& value,
|
| 531 |
-
const Allocator& = Allocator());
|
| 532 |
```
|
| 533 |
|
| 534 |
*Effects:* Constructs a `deque` with `n` copies of `value`, using the
|
| 535 |
specified allocator.
|
| 536 |
|
|
@@ -538,12 +557,11 @@ specified allocator.
|
|
| 538 |
|
| 539 |
*Complexity:* Linear in `n`.
|
| 540 |
|
| 541 |
``` cpp
|
| 542 |
template <class InputIterator>
|
| 543 |
-
deque(InputIterator first, InputIterator last,
|
| 544 |
-
const Allocator& = Allocator());
|
| 545 |
```
|
| 546 |
|
| 547 |
*Effects:* Constructs a `deque` equal to the range \[`first`, `last`),
|
| 548 |
using the specified allocator.
|
| 549 |
|
|
@@ -553,38 +571,47 @@ using the specified allocator.
|
|
| 553 |
|
| 554 |
``` cpp
|
| 555 |
void resize(size_type sz);
|
| 556 |
```
|
| 557 |
|
| 558 |
-
*Effects:* If `sz <
|
| 559 |
-
|
| 560 |
-
|
| 561 |
|
| 562 |
*Requires:* `T` shall be `MoveInsertable` and `DefaultInsertable` into
|
| 563 |
`*this`.
|
| 564 |
|
| 565 |
``` cpp
|
| 566 |
void resize(size_type sz, const T& c);
|
| 567 |
```
|
| 568 |
|
| 569 |
-
*Effects:* If `sz <
|
| 570 |
-
|
| 571 |
-
|
| 572 |
|
| 573 |
*Requires:* `T` shall be `CopyInsertable` into `*this`.
|
| 574 |
|
| 575 |
``` cpp
|
| 576 |
void shrink_to_fit();
|
| 577 |
```
|
| 578 |
|
| 579 |
*Requires:* `T` shall be `MoveInsertable` into `*this`.
|
| 580 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 581 |
*Complexity:* Linear in the size of the sequence.
|
| 582 |
|
| 583 |
-
*Remarks:* `shrink_to_fit`
|
| 584 |
-
|
| 585 |
-
|
| 586 |
|
| 587 |
#### `deque` modifiers <a id="deque.modifiers">[[deque.modifiers]]</a>
|
| 588 |
|
| 589 |
``` cpp
|
| 590 |
iterator insert(const_iterator position, const T& x);
|
|
@@ -593,12 +620,12 @@ iterator insert(const_iterator position, size_type n, const T& x);
|
|
| 593 |
template <class InputIterator>
|
| 594 |
iterator insert(const_iterator position,
|
| 595 |
InputIterator first, InputIterator last);
|
| 596 |
iterator insert(const_iterator position, initializer_list<T>);
|
| 597 |
|
| 598 |
-
template <class... Args>
|
| 599 |
-
template <class... Args>
|
| 600 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 601 |
void push_front(const T& x);
|
| 602 |
void push_front(T&& x);
|
| 603 |
void push_back(const T& x);
|
| 604 |
void push_back(T&& x);
|
|
@@ -623,54 +650,58 @@ a deque always takes constant time and causes a single call to a
|
|
| 623 |
constructor of `T`.
|
| 624 |
|
| 625 |
``` cpp
|
| 626 |
iterator erase(const_iterator position);
|
| 627 |
iterator erase(const_iterator first, const_iterator last);
|
|
|
|
|
|
|
| 628 |
```
|
| 629 |
|
| 630 |
*Effects:* An erase operation that erases the last element of a deque
|
| 631 |
invalidates only the past-the-end iterator and all iterators and
|
| 632 |
references to the erased elements. An erase operation that erases the
|
| 633 |
-
first element of a deque but not the last element invalidates only
|
| 634 |
-
erased elements. An erase operation that
|
| 635 |
-
element nor the last element of a deque
|
| 636 |
-
iterator and all iterators and references
|
| 637 |
-
deque.
|
| 638 |
|
| 639 |
-
*
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 643 |
|
| 644 |
*Throws:* Nothing unless an exception is thrown by the copy constructor,
|
| 645 |
move constructor, assignment operator, or move assignment operator of
|
| 646 |
`T`.
|
| 647 |
|
| 648 |
#### `deque` specialized algorithms <a id="deque.special">[[deque.special]]</a>
|
| 649 |
|
| 650 |
``` cpp
|
| 651 |
template <class T, class Allocator>
|
| 652 |
-
void swap(deque<T,Allocator>& x, deque<T,Allocator>& y)
|
|
|
|
| 653 |
```
|
| 654 |
|
| 655 |
-
*Effects:*
|
| 656 |
-
|
| 657 |
-
``` cpp
|
| 658 |
-
x.swap(y);
|
| 659 |
-
```
|
| 660 |
|
| 661 |
### Class template `forward_list` <a id="forwardlist">[[forwardlist]]</a>
|
| 662 |
|
| 663 |
#### Class template `forward_list` overview <a id="forwardlist.overview">[[forwardlist.overview]]</a>
|
| 664 |
|
| 665 |
A `forward_list` is a container that supports forward iterators and
|
| 666 |
allows constant time insert and erase operations anywhere within the
|
| 667 |
sequence, with storage management handled automatically. Fast random
|
| 668 |
-
access to list elements is not supported.
|
| 669 |
-
|
| 670 |
-
|
| 671 |
-
|
|
|
|
| 672 |
|
| 673 |
A `forward_list` satisfies all of the requirements of a container
|
| 674 |
(Table [[tab:containers.container.requirements]]), except that the
|
| 675 |
`size()` member function is not provided and `operator==` has linear
|
| 676 |
complexity. A `forward_list` also satisfies all of the requirements for
|
|
@@ -680,34 +711,34 @@ In addition, a `forward_list` provides the `assign` member functions
|
|
| 680 |
optional container requirements (Table
|
| 681 |
[[tab:containers.sequence.optional]]). Descriptions are provided here
|
| 682 |
only for operations on `forward_list` that are not described in that
|
| 683 |
table or for operations where there is additional semantic information.
|
| 684 |
|
| 685 |
-
Modifying any list requires access to the element preceding
|
| 686 |
-
element of interest, but in a `forward_list` there is no
|
| 687 |
-
way to access a preceding element. For this reason, ranges
|
| 688 |
-
modified, such as those supplied to `erase` and `splice`, must
|
| 689 |
-
at the beginning.
|
| 690 |
|
| 691 |
``` cpp
|
| 692 |
namespace std {
|
| 693 |
template <class T, class Allocator = allocator<T>>
|
| 694 |
class forward_list {
|
| 695 |
public:
|
| 696 |
// types:
|
| 697 |
-
|
| 698 |
-
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
|
| 702 |
-
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
|
| 706 |
-
|
| 707 |
|
| 708 |
-
// [forwardlist.cons], construct/copy/destroy
|
| 709 |
forward_list() : forward_list(Allocator()) { }
|
| 710 |
explicit forward_list(const Allocator&);
|
| 711 |
explicit forward_list(size_type n, const Allocator& = Allocator());
|
| 712 |
forward_list(size_type n, const T& value,
|
| 713 |
const Allocator& = Allocator());
|
|
@@ -719,19 +750,20 @@ namespace std {
|
|
| 719 |
forward_list(const forward_list& x, const Allocator&);
|
| 720 |
forward_list(forward_list&& x, const Allocator&);
|
| 721 |
forward_list(initializer_list<T>, const Allocator& = Allocator());
|
| 722 |
~forward_list();
|
| 723 |
forward_list& operator=(const forward_list& x);
|
| 724 |
-
forward_list& operator=(forward_list&& x)
|
|
|
|
| 725 |
forward_list& operator=(initializer_list<T>);
|
| 726 |
template <class InputIterator>
|
| 727 |
void assign(InputIterator first, InputIterator last);
|
| 728 |
void assign(size_type n, const T& t);
|
| 729 |
void assign(initializer_list<T>);
|
| 730 |
allocator_type get_allocator() const noexcept;
|
| 731 |
|
| 732 |
-
// [forwardlist.iter], iterators
|
| 733 |
iterator before_begin() noexcept;
|
| 734 |
const_iterator before_begin() const noexcept;
|
| 735 |
iterator begin() noexcept;
|
| 736 |
const_iterator begin() const noexcept;
|
| 737 |
iterator end() noexcept;
|
|
@@ -743,16 +775,16 @@ namespace std {
|
|
| 743 |
|
| 744 |
// capacity:
|
| 745 |
bool empty() const noexcept;
|
| 746 |
size_type max_size() const noexcept;
|
| 747 |
|
| 748 |
-
// [forwardlist.access], element access
|
| 749 |
reference front();
|
| 750 |
const_reference front() const;
|
| 751 |
|
| 752 |
-
// [forwardlist.modifiers], modifiers
|
| 753 |
-
template <class... Args>
|
| 754 |
void push_front(const T& x);
|
| 755 |
void push_front(T&& x);
|
| 756 |
void pop_front();
|
| 757 |
|
| 758 |
template <class... Args> iterator emplace_after(const_iterator position, Args&&... args);
|
|
@@ -764,17 +796,18 @@ namespace std {
|
|
| 764 |
iterator insert_after(const_iterator position, InputIterator first, InputIterator last);
|
| 765 |
iterator insert_after(const_iterator position, initializer_list<T> il);
|
| 766 |
|
| 767 |
iterator erase_after(const_iterator position);
|
| 768 |
iterator erase_after(const_iterator position, const_iterator last);
|
| 769 |
-
void swap(forward_list&)
|
|
|
|
| 770 |
|
| 771 |
void resize(size_type sz);
|
| 772 |
void resize(size_type sz, const value_type& c);
|
| 773 |
void clear() noexcept;
|
| 774 |
|
| 775 |
-
// [forwardlist.ops], forward_list operations
|
| 776 |
void splice_after(const_iterator position, forward_list& x);
|
| 777 |
void splice_after(const_iterator position, forward_list&& x);
|
| 778 |
void splice_after(const_iterator position, forward_list& x,
|
| 779 |
const_iterator i);
|
| 780 |
void splice_after(const_iterator position, forward_list&& x,
|
|
@@ -799,11 +832,15 @@ namespace std {
|
|
| 799 |
template <class Compare> void sort(Compare comp);
|
| 800 |
|
| 801 |
void reverse() noexcept;
|
| 802 |
};
|
| 803 |
|
| 804 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 805 |
template <class T, class Allocator>
|
| 806 |
bool operator==(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 807 |
template <class T, class Allocator>
|
| 808 |
bool operator< (const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 809 |
template <class T, class Allocator>
|
|
@@ -813,16 +850,23 @@ namespace std {
|
|
| 813 |
template <class T, class Allocator>
|
| 814 |
bool operator>=(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 815 |
template <class T, class Allocator>
|
| 816 |
bool operator<=(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 817 |
|
| 818 |
-
// [forwardlist.spec], specialized algorithms
|
| 819 |
template <class T, class Allocator>
|
| 820 |
-
void swap(forward_list<T,Allocator>& x, forward_list<T,Allocator>& y)
|
|
|
|
| 821 |
}
|
| 822 |
```
|
| 823 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 824 |
#### `forward_list` constructors, copy, assignment <a id="forwardlist.cons">[[forwardlist.cons]]</a>
|
| 825 |
|
| 826 |
``` cpp
|
| 827 |
explicit forward_list(const Allocator&);
|
| 828 |
```
|
|
@@ -899,11 +943,11 @@ elements into a `forward_list` is linear in `n`, and the number of calls
|
|
| 899 |
to the copy or move constructor of `T` is exactly equal to `n`. Erasing
|
| 900 |
`n` elements from a `forward_list` is linear in `n` and the number of
|
| 901 |
calls to the destructor of type `T` is exactly equal to `n`.
|
| 902 |
|
| 903 |
``` cpp
|
| 904 |
-
template <class... Args>
|
| 905 |
```
|
| 906 |
|
| 907 |
*Effects:* Inserts an object of type `value_type` constructed with
|
| 908 |
`value_type(std::forward<Args>(args)...)` at the beginning of the list.
|
| 909 |
|
|
@@ -916,11 +960,11 @@ void push_front(T&& x);
|
|
| 916 |
|
| 917 |
``` cpp
|
| 918 |
void pop_front();
|
| 919 |
```
|
| 920 |
|
| 921 |
-
*Effects:* `erase_after(before_begin())`
|
| 922 |
|
| 923 |
``` cpp
|
| 924 |
iterator insert_after(const_iterator position, const T& x);
|
| 925 |
iterator insert_after(const_iterator position, T&& x);
|
| 926 |
```
|
|
@@ -1023,14 +1067,12 @@ end of the list.
|
|
| 1023 |
void resize(size_type sz, const value_type& c);
|
| 1024 |
```
|
| 1025 |
|
| 1026 |
*Effects:* If `sz < distance(begin(), end())`, erases the last
|
| 1027 |
`distance(begin(), end()) - sz` elements from the list. Otherwise,
|
| 1028 |
-
inserts `sz - distance(begin(), end())`
|
| 1029 |
-
|
| 1030 |
-
to calling
|
| 1031 |
-
`allocator_traits<allocator_type>::construct(get_allocator(), std::addressof(e), c)`.
|
| 1032 |
|
| 1033 |
*Requires:* `T` shall be `CopyInsertable` into `*this`.
|
| 1034 |
|
| 1035 |
``` cpp
|
| 1036 |
void clear() noexcept;
|
|
@@ -1057,11 +1099,11 @@ those same elements but as members of `*this`. Iterators referring to
|
|
| 1057 |
the moved elements will continue to refer to their elements, but they
|
| 1058 |
now behave as iterators into `*this`, not into `x`.
|
| 1059 |
|
| 1060 |
*Throws:* Nothing.
|
| 1061 |
|
| 1062 |
-
*Complexity:* 𝑂(distance(x.begin(), x.end()))
|
| 1063 |
|
| 1064 |
``` cpp
|
| 1065 |
void splice_after(const_iterator position, forward_list& x, const_iterator i);
|
| 1066 |
void splice_after(const_iterator position, forward_list&& x, const_iterator i);
|
| 1067 |
```
|
|
@@ -1100,20 +1142,20 @@ dereferenceable. `position` is not an iterator in the range (`first`,
|
|
| 1100 |
the moved elements of `x` now refer to those same elements but as
|
| 1101 |
members of `*this`. Iterators referring to the moved elements will
|
| 1102 |
continue to refer to their elements, but they now behave as iterators
|
| 1103 |
into `*this`, not into `x`.
|
| 1104 |
|
| 1105 |
-
*Complexity:* 𝑂(distance(first, last))
|
| 1106 |
|
| 1107 |
``` cpp
|
| 1108 |
void remove(const T& value);
|
| 1109 |
template <class Predicate> void remove_if(Predicate pred);
|
| 1110 |
```
|
| 1111 |
|
| 1112 |
*Effects:* Erases all the elements in the list referred by a list
|
| 1113 |
iterator `i` for which the following conditions hold: `*i == value` (for
|
| 1114 |
-
`remove()`), `pred(*i)` is true (for `remove_if()`). Invalidates only
|
| 1115 |
the iterators and references to the erased elements.
|
| 1116 |
|
| 1117 |
*Throws:* Nothing unless an exception is thrown by the equality
|
| 1118 |
comparison or the predicate.
|
| 1119 |
|
|
@@ -1159,11 +1201,11 @@ references to the moved elements of `x` now refer to those same elements
|
|
| 1159 |
but as members of `*this`. Iterators referring to the moved elements
|
| 1160 |
will continue to refer to their elements, but they now behave as
|
| 1161 |
iterators into `*this`, not into `x`.
|
| 1162 |
|
| 1163 |
*Remarks:* Stable ([[algorithm.stable]]). The behavior is undefined if
|
| 1164 |
-
`
|
| 1165 |
|
| 1166 |
*Complexity:* At most
|
| 1167 |
`distance(begin(), end()) + distance(x.begin(), x.end()) - 1`
|
| 1168 |
comparisons.
|
| 1169 |
|
|
@@ -1175,11 +1217,11 @@ template <class Compare> void sort(Compare comp);
|
|
| 1175 |
*Requires:* `operator<` (for the version with no arguments) or `comp`
|
| 1176 |
(for the version with a comparison argument) defines a strict weak
|
| 1177 |
ordering ([[alg.sorting]]).
|
| 1178 |
|
| 1179 |
*Effects:* Sorts the list according to the `operator<` or the `comp`
|
| 1180 |
-
function object. If an exception is thrown the order of the elements in
|
| 1181 |
`*this` is unspecified. Does not affect the validity of iterators and
|
| 1182 |
references.
|
| 1183 |
|
| 1184 |
*Remarks:* Stable ([[algorithm.stable]]).
|
| 1185 |
|
|
@@ -1197,14 +1239,15 @@ affect the validity of iterators and references.
|
|
| 1197 |
|
| 1198 |
#### `forward_list` specialized algorithms <a id="forwardlist.spec">[[forwardlist.spec]]</a>
|
| 1199 |
|
| 1200 |
``` cpp
|
| 1201 |
template <class T, class Allocator>
|
| 1202 |
-
void swap(forward_list<T,Allocator>& x, forward_list<T,Allocator>& y)
|
|
|
|
| 1203 |
```
|
| 1204 |
|
| 1205 |
-
*Effects:* `x.swap(y)`
|
| 1206 |
|
| 1207 |
### Class template `list` <a id="list">[[list]]</a>
|
| 1208 |
|
| 1209 |
#### Class template `list` overview <a id="list.overview">[[list.overview]]</a>
|
| 1210 |
|
|
@@ -1230,24 +1273,24 @@ information.
|
|
| 1230 |
namespace std {
|
| 1231 |
template <class T, class Allocator = allocator<T>>
|
| 1232 |
class list {
|
| 1233 |
public:
|
| 1234 |
// types:
|
| 1235 |
-
|
| 1236 |
-
|
| 1237 |
-
|
| 1238 |
-
|
| 1239 |
-
|
| 1240 |
-
|
| 1241 |
-
|
| 1242 |
-
|
| 1243 |
-
|
| 1244 |
-
|
| 1245 |
-
|
| 1246 |
-
|
| 1247 |
|
| 1248 |
-
// [list.cons], construct/copy/destroy
|
| 1249 |
list() : list(Allocator()) { }
|
| 1250 |
explicit list(const Allocator&);
|
| 1251 |
explicit list(size_type n, const Allocator& = Allocator());
|
| 1252 |
list(size_type n, const T& value, const Allocator& = Allocator());
|
| 1253 |
template <class InputIterator>
|
|
@@ -1257,11 +1300,12 @@ namespace std {
|
|
| 1257 |
list(const list&, const Allocator&);
|
| 1258 |
list(list&&, const Allocator&);
|
| 1259 |
list(initializer_list<T>, const Allocator& = Allocator());
|
| 1260 |
~list();
|
| 1261 |
list& operator=(const list& x);
|
| 1262 |
-
list& operator=(list&& x)
|
|
|
|
| 1263 |
list& operator=(initializer_list<T>);
|
| 1264 |
template <class InputIterator>
|
| 1265 |
void assign(InputIterator first, InputIterator last);
|
| 1266 |
void assign(size_type n, const T& t);
|
| 1267 |
void assign(initializer_list<T>);
|
|
@@ -1280,11 +1324,11 @@ namespace std {
|
|
| 1280 |
const_iterator cbegin() const noexcept;
|
| 1281 |
const_iterator cend() const noexcept;
|
| 1282 |
const_reverse_iterator crbegin() const noexcept;
|
| 1283 |
const_reverse_iterator crend() const noexcept;
|
| 1284 |
|
| 1285 |
-
// [list.capacity], capacity
|
| 1286 |
bool empty() const noexcept;
|
| 1287 |
size_type size() const noexcept;
|
| 1288 |
size_type max_size() const noexcept;
|
| 1289 |
void resize(size_type sz);
|
| 1290 |
void resize(size_type sz, const T& c);
|
|
@@ -1293,16 +1337,16 @@ namespace std {
|
|
| 1293 |
reference front();
|
| 1294 |
const_reference front() const;
|
| 1295 |
reference back();
|
| 1296 |
const_reference back() const;
|
| 1297 |
|
| 1298 |
-
// [list.modifiers], modifiers
|
| 1299 |
-
template <class... Args>
|
| 1300 |
-
|
| 1301 |
-
template <class... Args> void emplace_back(Args&&... args);
|
| 1302 |
void push_front(const T& x);
|
| 1303 |
void push_front(T&& x);
|
|
|
|
| 1304 |
void push_back(const T& x);
|
| 1305 |
void push_back(T&& x);
|
| 1306 |
void pop_back();
|
| 1307 |
|
| 1308 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
|
@@ -1314,14 +1358,15 @@ namespace std {
|
|
| 1314 |
InputIterator last);
|
| 1315 |
iterator insert(const_iterator position, initializer_list<T> il);
|
| 1316 |
|
| 1317 |
iterator erase(const_iterator position);
|
| 1318 |
iterator erase(const_iterator position, const_iterator last);
|
| 1319 |
-
void swap(list&)
|
|
|
|
| 1320 |
void clear() noexcept;
|
| 1321 |
|
| 1322 |
-
// [list.ops], list operations
|
| 1323 |
void splice(const_iterator position, list& x);
|
| 1324 |
void splice(const_iterator position, list&& x);
|
| 1325 |
void splice(const_iterator position, list& x, const_iterator i);
|
| 1326 |
void splice(const_iterator position, list&& x, const_iterator i);
|
| 1327 |
void splice(const_iterator position, list& x,
|
|
@@ -1345,10 +1390,15 @@ namespace std {
|
|
| 1345 |
template <class Compare> void sort(Compare comp);
|
| 1346 |
|
| 1347 |
void reverse() noexcept;
|
| 1348 |
};
|
| 1349 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1350 |
template <class T, class Allocator>
|
| 1351 |
bool operator==(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 1352 |
template <class T, class Allocator>
|
| 1353 |
bool operator< (const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 1354 |
template <class T, class Allocator>
|
|
@@ -1358,16 +1408,22 @@ namespace std {
|
|
| 1358 |
template <class T, class Allocator>
|
| 1359 |
bool operator>=(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 1360 |
template <class T, class Allocator>
|
| 1361 |
bool operator<=(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 1362 |
|
| 1363 |
-
// specialized algorithms
|
| 1364 |
template <class T, class Allocator>
|
| 1365 |
-
void swap(list<T,Allocator>& x, list<T,Allocator>& y)
|
|
|
|
| 1366 |
}
|
| 1367 |
```
|
| 1368 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1369 |
#### `list` constructors, copy, and assignment <a id="list.cons">[[list.cons]]</a>
|
| 1370 |
|
| 1371 |
``` cpp
|
| 1372 |
explicit list(const Allocator&);
|
| 1373 |
```
|
|
@@ -1386,12 +1442,11 @@ the specified allocator.
|
|
| 1386 |
*Requires:* `T` shall be `DefaultInsertable` into `*this`.
|
| 1387 |
|
| 1388 |
*Complexity:* Linear in `n`.
|
| 1389 |
|
| 1390 |
``` cpp
|
| 1391 |
-
list(size_type n, const T& value,
|
| 1392 |
-
const Allocator& = Allocator());
|
| 1393 |
```
|
| 1394 |
|
| 1395 |
*Effects:* Constructs a `list` with `n` copies of `value`, using the
|
| 1396 |
specified allocator.
|
| 1397 |
|
|
@@ -1399,12 +1454,11 @@ specified allocator.
|
|
| 1399 |
|
| 1400 |
*Complexity:* Linear in `n`.
|
| 1401 |
|
| 1402 |
``` cpp
|
| 1403 |
template <class InputIterator>
|
| 1404 |
-
list(InputIterator first, InputIterator last,
|
| 1405 |
-
const Allocator& = Allocator());
|
| 1406 |
```
|
| 1407 |
|
| 1408 |
*Effects:* Constructs a `list` equal to the range \[`first`, `last`).
|
| 1409 |
|
| 1410 |
*Complexity:* Linear in `distance(first, last)`.
|
|
@@ -1414,11 +1468,11 @@ list(InputIterator first, InputIterator last,
|
|
| 1414 |
``` cpp
|
| 1415 |
void resize(size_type sz);
|
| 1416 |
```
|
| 1417 |
|
| 1418 |
*Effects:* If `size() < sz`, appends `sz - size()` default-inserted
|
| 1419 |
-
elements to the sequence. If `sz <= size()`, equivalent to
|
| 1420 |
|
| 1421 |
``` cpp
|
| 1422 |
list<T>::iterator it = begin();
|
| 1423 |
advance(it, sz);
|
| 1424 |
erase(it, end());
|
|
@@ -1428,11 +1482,11 @@ erase(it, end());
|
|
| 1428 |
|
| 1429 |
``` cpp
|
| 1430 |
void resize(size_type sz, const T& c);
|
| 1431 |
```
|
| 1432 |
|
| 1433 |
-
*Effects:*
|
| 1434 |
|
| 1435 |
``` cpp
|
| 1436 |
if (sz > size())
|
| 1437 |
insert(end(), sz-size(), c);
|
| 1438 |
else if (sz < size()) {
|
|
@@ -1455,12 +1509,12 @@ iterator insert(const_iterator position, size_type n, const T& x);
|
|
| 1455 |
template <class InputIterator>
|
| 1456 |
iterator insert(const_iterator position, InputIterator first,
|
| 1457 |
InputIterator last);
|
| 1458 |
iterator insert(const_iterator position, initializer_list<T>);
|
| 1459 |
|
| 1460 |
-
template <class... Args>
|
| 1461 |
-
template <class... Args>
|
| 1462 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 1463 |
void push_front(const T& x);
|
| 1464 |
void push_front(T&& x);
|
| 1465 |
void push_back(const T& x);
|
| 1466 |
void push_back(T&& x);
|
|
@@ -1524,19 +1578,19 @@ now behave as iterators into `*this`, not into `x`.
|
|
| 1524 |
``` cpp
|
| 1525 |
void splice(const_iterator position, list& x, const_iterator i);
|
| 1526 |
void splice(const_iterator position, list&& x, const_iterator i);
|
| 1527 |
```
|
| 1528 |
|
|
|
|
|
|
|
| 1529 |
*Effects:* Inserts an element pointed to by `i` from list `x` before
|
| 1530 |
`position` and removes the element from `x`. The result is unchanged if
|
| 1531 |
`position == i` or `position == ++i`. Pointers and references to `*i`
|
| 1532 |
continue to refer to this same element but as a member of `*this`.
|
| 1533 |
Iterators to `*i` (including `i` itself) continue to refer to the same
|
| 1534 |
element, but now behave as iterators into `*this`, not into `x`.
|
| 1535 |
|
| 1536 |
-
*Requires:* `i` is a valid dereferenceable iterator of `x`.
|
| 1537 |
-
|
| 1538 |
*Throws:* Nothing.
|
| 1539 |
|
| 1540 |
*Complexity:* Constant time.
|
| 1541 |
|
| 1542 |
``` cpp
|
|
@@ -1544,19 +1598,20 @@ void splice(const_iterator position, list& x, const_iterator first,
|
|
| 1544 |
const_iterator last);
|
| 1545 |
void splice(const_iterator position, list&& x, const_iterator first,
|
| 1546 |
const_iterator last);
|
| 1547 |
```
|
| 1548 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1549 |
*Effects:* Inserts elements in the range \[`first`, `last`) before
|
| 1550 |
-
`position` and removes the elements from `x`.
|
| 1551 |
-
|
| 1552 |
-
|
| 1553 |
-
|
| 1554 |
-
|
| 1555 |
-
same elements but as members of `*this`. Iterators referring to the
|
| 1556 |
-
moved elements will continue to refer to their elements, but they now
|
| 1557 |
-
behave as iterators into `*this`, not into `x`.
|
| 1558 |
|
| 1559 |
*Throws:* Nothing.
|
| 1560 |
|
| 1561 |
*Complexity:* Constant time if `&x == this`; otherwise, linear time.
|
| 1562 |
|
|
@@ -1611,20 +1666,20 @@ shall be sorted according to this ordering.
|
|
| 1611 |
*Effects:* If `(&x == this)` does nothing; otherwise, merges the two
|
| 1612 |
sorted ranges `[begin(), end())` and `[x.begin(), x.end())`. The result
|
| 1613 |
is a range in which the elements will be sorted in non-decreasing order
|
| 1614 |
according to the ordering defined by `comp`; that is, for every iterator
|
| 1615 |
`i`, in the range other than the first, the condition
|
| 1616 |
-
`comp(*i, *(i - 1))` will be false. Pointers and references to the
|
| 1617 |
-
elements of `x` now refer to those same elements but as members of
|
| 1618 |
`*this`. Iterators referring to the moved elements will continue to
|
| 1619 |
refer to their elements, but they now behave as iterators into `*this`,
|
| 1620 |
not into `x`.
|
| 1621 |
|
| 1622 |
*Remarks:* Stable ([[algorithm.stable]]). If `(&x != this)` the range
|
| 1623 |
`[x.begin(), x.end())` is empty after the merge. No elements are copied
|
| 1624 |
by this operation. The behavior is undefined if
|
| 1625 |
-
`
|
| 1626 |
|
| 1627 |
*Complexity:* At most `size() + x.size() - 1` applications of `comp` if
|
| 1628 |
`(&x != this)`; otherwise, no applications of `comp` are performed. If
|
| 1629 |
an exception is thrown other than by a comparison there are no effects.
|
| 1630 |
|
|
@@ -1644,89 +1699,85 @@ template <class Compare> void sort(Compare comp);
|
|
| 1644 |
|
| 1645 |
*Requires:* `operator<` (for the first version) or `comp` (for the
|
| 1646 |
second version) shall define a strict weak ordering ([[alg.sorting]]).
|
| 1647 |
|
| 1648 |
*Effects:* Sorts the list according to the `operator<` or a `Compare`
|
| 1649 |
-
function object.
|
|
|
|
| 1650 |
references.
|
| 1651 |
|
| 1652 |
*Remarks:* Stable ([[algorithm.stable]]).
|
| 1653 |
|
| 1654 |
-
*Complexity:* Approximately N log
|
| 1655 |
|
| 1656 |
#### `list` specialized algorithms <a id="list.special">[[list.special]]</a>
|
| 1657 |
|
| 1658 |
``` cpp
|
| 1659 |
template <class T, class Allocator>
|
| 1660 |
-
void swap(list<T,Allocator>& x, list<T,Allocator>& y)
|
|
|
|
| 1661 |
```
|
| 1662 |
|
| 1663 |
-
*Effects:*
|
| 1664 |
-
|
| 1665 |
-
``` cpp
|
| 1666 |
-
x.swap(y);
|
| 1667 |
-
```
|
| 1668 |
|
| 1669 |
### Class template `vector` <a id="vector">[[vector]]</a>
|
| 1670 |
|
| 1671 |
#### Class template `vector` overview <a id="vector.overview">[[vector.overview]]</a>
|
| 1672 |
|
| 1673 |
-
A `vector` is a sequence container that supports
|
| 1674 |
-
|
| 1675 |
-
|
| 1676 |
-
|
| 1677 |
-
given to improve efficiency. The elements of a vector are stored
|
| 1678 |
-
contiguously, meaning that if `v` is a `vector<T, Allocator>` where `T`
|
| 1679 |
-
is some type other than `bool`, then it obeys the identity
|
| 1680 |
-
`&v[n] == &v[0] + n` for all `0 <= n < v.size()`.
|
| 1681 |
|
| 1682 |
A `vector` satisfies all of the requirements of a container and of a
|
| 1683 |
reversible container (given in two tables in
|
| 1684 |
[[container.requirements]]), of a sequence container, including most of
|
| 1685 |
-
the optional sequence container requirements ([[sequence.reqmts]]),
|
| 1686 |
-
|
| 1687 |
-
|
| 1688 |
-
|
| 1689 |
-
|
| 1690 |
-
|
| 1691 |
-
|
|
|
|
| 1692 |
|
| 1693 |
``` cpp
|
| 1694 |
namespace std {
|
| 1695 |
template <class T, class Allocator = allocator<T>>
|
| 1696 |
class vector {
|
| 1697 |
public:
|
| 1698 |
// types:
|
| 1699 |
-
|
| 1700 |
-
|
| 1701 |
-
|
| 1702 |
-
|
| 1703 |
-
|
| 1704 |
-
|
| 1705 |
-
|
| 1706 |
-
|
| 1707 |
-
|
| 1708 |
-
|
| 1709 |
-
|
| 1710 |
-
|
| 1711 |
|
| 1712 |
-
// [vector.cons], construct/copy/destroy
|
| 1713 |
-
vector() : vector(Allocator()) { }
|
| 1714 |
-
explicit vector(const Allocator&);
|
| 1715 |
explicit vector(size_type n, const Allocator& = Allocator());
|
| 1716 |
vector(size_type n, const T& value, const Allocator& = Allocator());
|
| 1717 |
template <class InputIterator>
|
| 1718 |
-
vector(InputIterator first, InputIterator last,
|
| 1719 |
-
const Allocator& = Allocator());
|
| 1720 |
vector(const vector& x);
|
| 1721 |
-
vector(vector&&);
|
| 1722 |
vector(const vector&, const Allocator&);
|
| 1723 |
vector(vector&&, const Allocator&);
|
| 1724 |
vector(initializer_list<T>, const Allocator& = Allocator());
|
| 1725 |
~vector();
|
| 1726 |
vector& operator=(const vector& x);
|
| 1727 |
-
vector& operator=(vector&& x)
|
|
|
|
|
|
|
| 1728 |
vector& operator=(initializer_list<T>);
|
| 1729 |
template <class InputIterator>
|
| 1730 |
void assign(InputIterator first, InputIterator last);
|
| 1731 |
void assign(size_type n, const T& u);
|
| 1732 |
void assign(initializer_list<T>);
|
|
@@ -1745,17 +1796,17 @@ namespace std {
|
|
| 1745 |
const_iterator cbegin() const noexcept;
|
| 1746 |
const_iterator cend() const noexcept;
|
| 1747 |
const_reverse_iterator crbegin() const noexcept;
|
| 1748 |
const_reverse_iterator crend() const noexcept;
|
| 1749 |
|
| 1750 |
-
// [vector.capacity], capacity
|
|
|
|
| 1751 |
size_type size() const noexcept;
|
| 1752 |
size_type max_size() const noexcept;
|
|
|
|
| 1753 |
void resize(size_type sz);
|
| 1754 |
void resize(size_type sz, const T& c);
|
| 1755 |
-
size_type capacity() const noexcept;
|
| 1756 |
-
bool empty() const noexcept;
|
| 1757 |
void reserve(size_type n);
|
| 1758 |
void shrink_to_fit();
|
| 1759 |
|
| 1760 |
// element access:
|
| 1761 |
reference operator[](size_type n);
|
|
@@ -1769,30 +1820,36 @@ namespace std {
|
|
| 1769 |
|
| 1770 |
// [vector.data], data access
|
| 1771 |
T* data() noexcept;
|
| 1772 |
const T* data() const noexcept;
|
| 1773 |
|
| 1774 |
-
// [vector.modifiers], modifiers
|
| 1775 |
-
template <class... Args>
|
| 1776 |
void push_back(const T& x);
|
| 1777 |
void push_back(T&& x);
|
| 1778 |
void pop_back();
|
| 1779 |
|
| 1780 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 1781 |
iterator insert(const_iterator position, const T& x);
|
| 1782 |
iterator insert(const_iterator position, T&& x);
|
| 1783 |
iterator insert(const_iterator position, size_type n, const T& x);
|
| 1784 |
template <class InputIterator>
|
| 1785 |
-
|
| 1786 |
-
InputIterator first, InputIterator last);
|
| 1787 |
iterator insert(const_iterator position, initializer_list<T> il);
|
| 1788 |
iterator erase(const_iterator position);
|
| 1789 |
iterator erase(const_iterator first, const_iterator last);
|
| 1790 |
-
void swap(vector&)
|
|
|
|
|
|
|
| 1791 |
void clear() noexcept;
|
| 1792 |
};
|
| 1793 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1794 |
template <class T, class Allocator>
|
| 1795 |
bool operator==(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 1796 |
template <class T, class Allocator>
|
| 1797 |
bool operator< (const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 1798 |
template <class T, class Allocator>
|
|
@@ -1802,16 +1859,22 @@ namespace std {
|
|
| 1802 |
template <class T, class Allocator>
|
| 1803 |
bool operator>=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 1804 |
template <class T, class Allocator>
|
| 1805 |
bool operator<=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 1806 |
|
| 1807 |
-
// [vector.special], specialized algorithms
|
| 1808 |
template <class T, class Allocator>
|
| 1809 |
-
void swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
|
|
|
|
| 1810 |
}
|
| 1811 |
```
|
| 1812 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1813 |
#### `vector` constructors, copy, and assignment <a id="vector.cons">[[vector.cons]]</a>
|
| 1814 |
|
| 1815 |
``` cpp
|
| 1816 |
explicit vector(const Allocator&);
|
| 1817 |
```
|
|
@@ -1852,13 +1915,13 @@ template <class InputIterator>
|
|
| 1852 |
*Effects:* Constructs a `vector` equal to the range \[`first`, `last`),
|
| 1853 |
using the specified allocator.
|
| 1854 |
|
| 1855 |
*Complexity:* Makes only N calls to the copy constructor of `T` (where N
|
| 1856 |
is the distance between `first` and `last`) and no reallocations if
|
| 1857 |
-
iterators first and last are of forward, bidirectional, or random
|
| 1858 |
-
categories. It makes order `N` calls to the copy constructor of
|
| 1859 |
-
order log
|
| 1860 |
|
| 1861 |
#### `vector` capacity <a id="vector.capacity">[[vector.capacity]]</a>
|
| 1862 |
|
| 1863 |
``` cpp
|
| 1864 |
size_type capacity() const noexcept;
|
|
@@ -1897,20 +1960,30 @@ vector greater than the value of `capacity()`.
|
|
| 1897 |
void shrink_to_fit();
|
| 1898 |
```
|
| 1899 |
|
| 1900 |
*Requires:* `T` shall be `MoveInsertable` into `*this`.
|
| 1901 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1902 |
*Complexity:* Linear in the size of the sequence.
|
| 1903 |
|
| 1904 |
-
*Remarks:*
|
| 1905 |
-
|
| 1906 |
-
|
| 1907 |
-
other than by the move constructor of a non-`CopyInsertable` `T` there
|
| 1908 |
-
are no effects.
|
| 1909 |
|
| 1910 |
``` cpp
|
| 1911 |
-
void swap(vector& x)
|
|
|
|
|
|
|
| 1912 |
```
|
| 1913 |
|
| 1914 |
*Effects:* Exchanges the contents and `capacity()` of `*this` with that
|
| 1915 |
of `x`.
|
| 1916 |
|
|
@@ -1918,13 +1991,13 @@ of `x`.
|
|
| 1918 |
|
| 1919 |
``` cpp
|
| 1920 |
void resize(size_type sz);
|
| 1921 |
```
|
| 1922 |
|
| 1923 |
-
*Effects:* If `sz <
|
| 1924 |
-
|
| 1925 |
-
|
| 1926 |
|
| 1927 |
*Requires:* `T` shall be `MoveInsertable` and `DefaultInsertable` into
|
| 1928 |
`*this`.
|
| 1929 |
|
| 1930 |
*Remarks:* If an exception is thrown other than by the move constructor
|
|
@@ -1932,13 +2005,13 @@ of a non-`CopyInsertable` `T` there are no effects.
|
|
| 1932 |
|
| 1933 |
``` cpp
|
| 1934 |
void resize(size_type sz, const T& c);
|
| 1935 |
```
|
| 1936 |
|
| 1937 |
-
*Effects:* If `sz <
|
| 1938 |
-
|
| 1939 |
-
|
| 1940 |
|
| 1941 |
*Requires:* `T` shall be `CopyInsertable` into `*this`.
|
| 1942 |
|
| 1943 |
*Remarks:* If an exception is thrown there are no effects.
|
| 1944 |
|
|
@@ -1948,11 +2021,11 @@ void resize(size_type sz, const T& c);
|
|
| 1948 |
T* data() noexcept;
|
| 1949 |
const T* data() const noexcept;
|
| 1950 |
```
|
| 1951 |
|
| 1952 |
*Returns:* A pointer such that \[`data()`, `data() + size()`) is a valid
|
| 1953 |
-
range. For a non-empty vector, `data()` `==` `
|
| 1954 |
|
| 1955 |
*Complexity:* Constant time.
|
| 1956 |
|
| 1957 |
#### `vector` modifiers <a id="vector.modifiers">[[vector.modifiers]]</a>
|
| 1958 |
|
|
@@ -1962,81 +2035,81 @@ iterator insert(const_iterator position, T&& x);
|
|
| 1962 |
iterator insert(const_iterator position, size_type n, const T& x);
|
| 1963 |
template <class InputIterator>
|
| 1964 |
iterator insert(const_iterator position, InputIterator first, InputIterator last);
|
| 1965 |
iterator insert(const_iterator position, initializer_list<T>);
|
| 1966 |
|
| 1967 |
-
template <class... Args>
|
| 1968 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 1969 |
void push_back(const T& x);
|
| 1970 |
void push_back(T&& x);
|
| 1971 |
```
|
| 1972 |
|
| 1973 |
*Remarks:* Causes reallocation if the new size is greater than the old
|
| 1974 |
-
capacity.
|
| 1975 |
-
|
| 1976 |
-
|
| 1977 |
-
|
| 1978 |
-
|
| 1979 |
-
|
| 1980 |
-
|
| 1981 |
-
|
| 1982 |
-
|
|
|
|
|
|
|
| 1983 |
|
| 1984 |
*Complexity:* The complexity is linear in the number of elements
|
| 1985 |
inserted plus the distance to the end of the vector.
|
| 1986 |
|
| 1987 |
``` cpp
|
| 1988 |
iterator erase(const_iterator position);
|
| 1989 |
iterator erase(const_iterator first, const_iterator last);
|
|
|
|
| 1990 |
```
|
| 1991 |
|
| 1992 |
*Effects:* Invalidates iterators and references at or after the point of
|
| 1993 |
the erase.
|
| 1994 |
|
| 1995 |
*Complexity:* The destructor of `T` is called the number of times equal
|
| 1996 |
-
to the number of the elements erased, but the
|
| 1997 |
-
|
| 1998 |
-
|
| 1999 |
|
| 2000 |
-
*Throws:* Nothing unless an exception is thrown by the
|
| 2001 |
-
|
| 2002 |
-
`T`.
|
| 2003 |
|
| 2004 |
#### `vector` specialized algorithms <a id="vector.special">[[vector.special]]</a>
|
| 2005 |
|
| 2006 |
``` cpp
|
| 2007 |
template <class T, class Allocator>
|
| 2008 |
-
void swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
|
|
|
|
| 2009 |
```
|
| 2010 |
|
| 2011 |
-
*Effects:*
|
| 2012 |
-
|
| 2013 |
-
``` cpp
|
| 2014 |
-
x.swap(y);
|
| 2015 |
-
```
|
| 2016 |
|
| 2017 |
### Class `vector<bool>` <a id="vector.bool">[[vector.bool]]</a>
|
| 2018 |
|
| 2019 |
To optimize space allocation, a specialization of vector for `bool`
|
| 2020 |
elements is provided:
|
| 2021 |
|
| 2022 |
``` cpp
|
| 2023 |
namespace std {
|
| 2024 |
-
template <class Allocator>
|
|
|
|
| 2025 |
public:
|
| 2026 |
// types:
|
| 2027 |
-
|
| 2028 |
-
|
| 2029 |
-
|
| 2030 |
-
|
| 2031 |
-
|
| 2032 |
-
|
| 2033 |
-
|
| 2034 |
-
|
| 2035 |
-
|
| 2036 |
-
|
| 2037 |
-
|
| 2038 |
|
| 2039 |
// bit reference:
|
| 2040 |
class reference {
|
| 2041 |
friend class vector;
|
| 2042 |
reference() noexcept;
|
|
@@ -2086,15 +2159,15 @@ namespace std {
|
|
| 2086 |
const_iterator cend() const noexcept;
|
| 2087 |
const_reverse_iterator crbegin() const noexcept;
|
| 2088 |
const_reverse_iterator crend() const noexcept;
|
| 2089 |
|
| 2090 |
// capacity:
|
|
|
|
| 2091 |
size_type size() const noexcept;
|
| 2092 |
size_type max_size() const noexcept;
|
|
|
|
| 2093 |
void resize(size_type sz, bool c = false);
|
| 2094 |
-
size_type capacity() const noexcept;
|
| 2095 |
-
bool empty() const noexcept;
|
| 2096 |
void reserve(size_type n);
|
| 2097 |
void shrink_to_fit();
|
| 2098 |
|
| 2099 |
// element access:
|
| 2100 |
reference operator[](size_type n);
|
|
@@ -2105,11 +2178,11 @@ namespace std {
|
|
| 2105 |
const_reference front() const;
|
| 2106 |
reference back();
|
| 2107 |
const_reference back() const;
|
| 2108 |
|
| 2109 |
// modifiers:
|
| 2110 |
-
template <class... Args>
|
| 2111 |
void push_back(const bool& x);
|
| 2112 |
void pop_back();
|
| 2113 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 2114 |
iterator insert(const_iterator position, const bool& x);
|
| 2115 |
iterator insert(const_iterator position, size_type n, const bool& x);
|
|
@@ -2129,21 +2202,21 @@ namespace std {
|
|
| 2129 |
```
|
| 2130 |
|
| 2131 |
Unless described below, all operations have the same requirements and
|
| 2132 |
semantics as the primary `vector` template, except that operations
|
| 2133 |
dealing with the `bool` value type map to bit values in the container
|
| 2134 |
-
storage and allocator_traits::construct (
|
| 2135 |
-
is not used to construct these values.
|
| 2136 |
|
| 2137 |
There is no requirement that the data be stored as a contiguous
|
| 2138 |
allocation of `bool` values. A space-optimized representation of bits is
|
| 2139 |
recommended instead.
|
| 2140 |
|
| 2141 |
`reference`
|
| 2142 |
|
| 2143 |
is a class that simulates the behavior of references of a single bit in
|
| 2144 |
-
`vector<bool>`. The conversion
|
| 2145 |
set, and `false` otherwise. The assignment operator sets the bit when
|
| 2146 |
the argument is (convertible to) `true` and clears it otherwise. `flip`
|
| 2147 |
reverses the state of the bit.
|
| 2148 |
|
| 2149 |
``` cpp
|
|
@@ -2154,11 +2227,11 @@ void flip() noexcept;
|
|
| 2154 |
|
| 2155 |
``` cpp
|
| 2156 |
static void swap(reference x, reference y) noexcept;
|
| 2157 |
```
|
| 2158 |
|
| 2159 |
-
*Effects:*
|
| 2160 |
|
| 2161 |
``` cpp
|
| 2162 |
bool b = x;
|
| 2163 |
x = y;
|
| 2164 |
y = b;
|
|
@@ -2166,8 +2239,7 @@ y = b;
|
|
| 2166 |
|
| 2167 |
``` cpp
|
| 2168 |
template <class Allocator> struct hash<vector<bool, Allocator>>;
|
| 2169 |
```
|
| 2170 |
|
| 2171 |
-
The
|
| 2172 |
-
template `hash` ([[unord.hash]]).
|
| 2173 |
|
|
|
|
| 1 |
## Sequence containers <a id="sequences">[[sequences]]</a>
|
| 2 |
|
| 3 |
### In general <a id="sequences.general">[[sequences.general]]</a>
|
| 4 |
|
| 5 |
The headers `<array>`, `<deque>`, `<forward_list>`, `<list>`, and
|
| 6 |
+
`<vector>` define class templates that meet the requirements for
|
| 7 |
sequence containers.
|
| 8 |
|
| 9 |
+
### Header `<array>` synopsis <a id="array.syn">[[array.syn]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
``` cpp
|
| 12 |
#include <initializer_list>
|
| 13 |
|
| 14 |
namespace std {
|
| 15 |
+
// [array], class template array
|
| 16 |
template <class T, size_t N> struct array;
|
| 17 |
template <class T, size_t N>
|
| 18 |
bool operator==(const array<T, N>& x, const array<T, N>& y);
|
| 19 |
template <class T, size_t N>
|
| 20 |
bool operator!=(const array<T, N>& x, const array<T, N>& y);
|
|
|
|
| 39 |
constexpr T& get(array<T, N>&) noexcept;
|
| 40 |
template <size_t I, class T, size_t N>
|
| 41 |
constexpr T&& get(array<T, N>&&) noexcept;
|
| 42 |
template <size_t I, class T, size_t N>
|
| 43 |
constexpr const T& get(const array<T, N>&) noexcept;
|
| 44 |
+
template <size_t I, class T, size_t N>
|
| 45 |
+
constexpr const T&& get(const array<T, N>&&) noexcept;
|
| 46 |
}
|
| 47 |
```
|
| 48 |
|
| 49 |
+
### Header `<deque>` synopsis <a id="deque.syn">[[deque.syn]]</a>
|
| 50 |
|
| 51 |
``` cpp
|
| 52 |
#include <initializer_list>
|
| 53 |
|
| 54 |
namespace std {
|
| 55 |
+
// [deque], class template deque
|
| 56 |
template <class T, class Allocator = allocator<T>> class deque;
|
| 57 |
template <class T, class Allocator>
|
| 58 |
bool operator==(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 59 |
template <class T, class Allocator>
|
| 60 |
bool operator< (const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
|
|
|
| 65 |
template <class T, class Allocator>
|
| 66 |
bool operator>=(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 67 |
template <class T, class Allocator>
|
| 68 |
bool operator<=(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 69 |
template <class T, class Allocator>
|
| 70 |
+
void swap(deque<T, Allocator>& x, deque<T, Allocator>& y)
|
| 71 |
+
noexcept(noexcept(x.swap(y)));
|
| 72 |
+
|
| 73 |
+
namespace pmr {
|
| 74 |
+
template <class T>
|
| 75 |
+
using deque = std::deque<T, polymorphic_allocator<T>>;
|
| 76 |
+
}
|
| 77 |
}
|
| 78 |
```
|
| 79 |
|
| 80 |
+
### Header `<forward_list>` synopsis <a id="forward_list.syn">[[forward_list.syn]]</a>
|
| 81 |
|
| 82 |
``` cpp
|
| 83 |
#include <initializer_list>
|
| 84 |
|
| 85 |
namespace std {
|
| 86 |
+
// [forwardlist], class template forward_list
|
| 87 |
template <class T, class Allocator = allocator<T>> class forward_list;
|
| 88 |
template <class T, class Allocator>
|
| 89 |
bool operator==(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 90 |
template <class T, class Allocator>
|
| 91 |
bool operator< (const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
|
|
|
| 96 |
template <class T, class Allocator>
|
| 97 |
bool operator>=(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 98 |
template <class T, class Allocator>
|
| 99 |
bool operator<=(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 100 |
template <class T, class Allocator>
|
| 101 |
+
void swap(forward_list<T, Allocator>& x, forward_list<T, Allocator>& y)
|
| 102 |
+
noexcept(noexcept(x.swap(y)));
|
| 103 |
+
|
| 104 |
+
namespace pmr {
|
| 105 |
+
template <class T>
|
| 106 |
+
using forward_list = std::forward_list<T, polymorphic_allocator<T>>;
|
| 107 |
+
}
|
| 108 |
}
|
| 109 |
```
|
| 110 |
|
| 111 |
+
### Header `<list>` synopsis <a id="list.syn">[[list.syn]]</a>
|
| 112 |
|
| 113 |
``` cpp
|
| 114 |
#include <initializer_list>
|
| 115 |
|
| 116 |
namespace std {
|
| 117 |
+
// [list], class template list
|
| 118 |
template <class T, class Allocator = allocator<T>> class list;
|
| 119 |
template <class T, class Allocator>
|
| 120 |
bool operator==(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 121 |
template <class T, class Allocator>
|
| 122 |
bool operator< (const list<T, Allocator>& x, const list<T, Allocator>& y);
|
|
|
|
| 127 |
template <class T, class Allocator>
|
| 128 |
bool operator>=(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 129 |
template <class T, class Allocator>
|
| 130 |
bool operator<=(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 131 |
template <class T, class Allocator>
|
| 132 |
+
void swap(list<T, Allocator>& x, list<T, Allocator>& y)
|
| 133 |
+
noexcept(noexcept(x.swap(y)));
|
| 134 |
+
|
| 135 |
+
namespace pmr {
|
| 136 |
+
template <class T>
|
| 137 |
+
using list = std::list<T, polymorphic_allocator<T>>;
|
| 138 |
+
}
|
| 139 |
}
|
| 140 |
```
|
| 141 |
|
| 142 |
+
### Header `<vector>` synopsis <a id="vector.syn">[[vector.syn]]</a>
|
| 143 |
|
| 144 |
``` cpp
|
| 145 |
#include <initializer_list>
|
| 146 |
|
| 147 |
namespace std {
|
| 148 |
+
// [vector], class template vector
|
| 149 |
template <class T, class Allocator = allocator<T>> class vector;
|
| 150 |
template <class T, class Allocator>
|
| 151 |
bool operator==(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 152 |
template <class T, class Allocator>
|
| 153 |
bool operator< (const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
|
|
|
| 158 |
template <class T, class Allocator>
|
| 159 |
bool operator>=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 160 |
template <class T, class Allocator>
|
| 161 |
bool operator<=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 162 |
template <class T, class Allocator>
|
| 163 |
+
void swap(vector<T, Allocator>& x, vector<T, Allocator>& y)
|
| 164 |
+
noexcept(noexcept(x.swap(y)));
|
| 165 |
|
| 166 |
+
// [vector.bool], class vector<bool>
|
| 167 |
template <class Allocator> class vector<bool, Allocator>;
|
| 168 |
|
| 169 |
// hash support
|
| 170 |
template <class T> struct hash;
|
| 171 |
template <class Allocator> struct hash<vector<bool, Allocator>>;
|
| 172 |
+
|
| 173 |
+
namespace pmr {
|
| 174 |
+
template <class T>
|
| 175 |
+
using vector = std::vector<T, polymorphic_allocator<T>>;
|
| 176 |
+
}
|
| 177 |
}
|
| 178 |
```
|
| 179 |
|
| 180 |
### Class template `array` <a id="array">[[array]]</a>
|
| 181 |
|
| 182 |
#### Class template `array` overview <a id="array.overview">[[array.overview]]</a>
|
| 183 |
|
| 184 |
The header `<array>` defines a class template for storing fixed-size
|
| 185 |
+
sequences of objects. An `array` is a contiguous container (
|
| 186 |
+
[[container.requirements.general]]). An instance of `array<T, N>` stores
|
| 187 |
+
`N` elements of type `T`, so that `size() == N` is an invariant.
|
|
|
|
|
|
|
| 188 |
|
| 189 |
+
An `array` is an aggregate ([[dcl.init.aggr]]) that can be
|
| 190 |
+
list-initialized with up to `N` elements whose types are convertible to
|
| 191 |
+
`T`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
An `array` satisfies all of the requirements of a container and of a
|
| 194 |
reversible container ([[container.requirements]]), except that a
|
| 195 |
default constructed `array` object is not empty and that `swap` does not
|
| 196 |
have constant complexity. An `array` satisfies some of the requirements
|
|
|
|
| 202 |
``` cpp
|
| 203 |
namespace std {
|
| 204 |
template <class T, size_t N>
|
| 205 |
struct array {
|
| 206 |
// types:
|
| 207 |
+
using value_type = T;
|
| 208 |
+
using pointer = T*;
|
| 209 |
+
using const_pointer = const T*;
|
| 210 |
+
using reference = T&;
|
| 211 |
+
using const_reference = const T&;
|
| 212 |
+
using size_type = size_t;
|
| 213 |
+
using difference_type = ptrdiff_t;
|
| 214 |
+
using iterator = implementation-defined // type of array::iterator; // see [container.requirements]
|
| 215 |
+
using const_iterator = implementation-defined // type of array::const_iterator; // see [container.requirements]
|
| 216 |
+
using reverse_iterator = std::reverse_iterator<iterator>;
|
| 217 |
+
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
|
|
|
|
|
|
| 218 |
|
| 219 |
// no explicit construct/copy/destroy for aggregate type
|
| 220 |
|
| 221 |
void fill(const T& u);
|
| 222 |
+
void swap(array&) noexcept(is_nothrow_swappable_v<T>);
|
| 223 |
|
| 224 |
// iterators:
|
| 225 |
+
constexpr iterator begin() noexcept;
|
| 226 |
+
constexpr const_iterator begin() const noexcept;
|
| 227 |
+
constexpr iterator end() noexcept;
|
| 228 |
+
constexpr const_iterator end() const noexcept;
|
| 229 |
|
| 230 |
+
constexpr reverse_iterator rbegin() noexcept;
|
| 231 |
+
constexpr const_reverse_iterator rbegin() const noexcept;
|
| 232 |
+
constexpr reverse_iterator rend() noexcept;
|
| 233 |
+
constexpr const_reverse_iterator rend() const noexcept;
|
| 234 |
|
| 235 |
+
constexpr const_iterator cbegin() const noexcept;
|
| 236 |
+
constexpr const_iterator cend() const noexcept;
|
| 237 |
+
constexpr const_reverse_iterator crbegin() const noexcept;
|
| 238 |
+
constexpr const_reverse_iterator crend() const noexcept;
|
| 239 |
|
| 240 |
// capacity:
|
| 241 |
+
constexpr bool empty() const noexcept;
|
| 242 |
constexpr size_type size() const noexcept;
|
| 243 |
constexpr size_type max_size() const noexcept;
|
|
|
|
| 244 |
|
| 245 |
// element access:
|
| 246 |
+
constexpr reference operator[](size_type n);
|
| 247 |
constexpr const_reference operator[](size_type n) const;
|
| 248 |
+
constexpr reference at(size_type n);
|
| 249 |
constexpr const_reference at(size_type n) const;
|
| 250 |
+
constexpr reference front();
|
| 251 |
constexpr const_reference front() const;
|
| 252 |
+
constexpr reference back();
|
| 253 |
constexpr const_reference back() const;
|
| 254 |
|
| 255 |
+
constexpr T * data() noexcept;
|
| 256 |
+
constexpr const T * data() const noexcept;
|
| 257 |
};
|
| 258 |
+
|
| 259 |
+
template<class T, class... U>
|
| 260 |
+
array(T, U...) -> array<T, 1 + sizeof...(U)>;
|
| 261 |
}
|
| 262 |
```
|
| 263 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
#### `array` constructors, copy, and assignment <a id="array.cons">[[array.cons]]</a>
|
| 265 |
|
| 266 |
The conditions for an aggregate ([[dcl.init.aggr]]) shall be met. Class
|
| 267 |
`array` relies on the implicitly-declared special member functions (
|
| 268 |
[[class.ctor]], [[class.dtor]], and [[class.copy]]) to conform to the
|
|
|
|
| 270 |
to the requirements specified in the container requirements table, the
|
| 271 |
implicit move constructor and move assignment operator for `array`
|
| 272 |
require that `T` be `MoveConstructible` or `MoveAssignable`,
|
| 273 |
respectively.
|
| 274 |
|
| 275 |
+
``` cpp
|
| 276 |
+
template<class T, class... U>
|
| 277 |
+
array(T, U...) -> array<T, 1 + sizeof...(U)>;
|
| 278 |
+
```
|
| 279 |
+
|
| 280 |
+
*Requires:* `(is_same_v<T, U> && ...)` is `true`. Otherwise the program
|
| 281 |
+
is ill-formed.
|
| 282 |
+
|
| 283 |
#### `array` specialized algorithms <a id="array.special">[[array.special]]</a>
|
| 284 |
|
| 285 |
``` cpp
|
| 286 |
+
template <class T, size_t N>
|
| 287 |
+
void swap(array<T, N>& x, array<T, N>& y) noexcept(noexcept(x.swap(y)));
|
| 288 |
```
|
| 289 |
|
| 290 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 291 |
+
unless `N == 0` or `is_swappable_v<T>` is `true`.
|
| 292 |
|
| 293 |
+
*Effects:* As if by `x.swap(y)`.
|
|
|
|
|
|
|
| 294 |
|
| 295 |
*Complexity:* Linear in `N`.
|
| 296 |
|
| 297 |
#### `array::size` <a id="array.size">[[array.size]]</a>
|
| 298 |
|
| 299 |
``` cpp
|
| 300 |
template <class T, size_t N> constexpr size_type array<T, N>::size() const noexcept;
|
| 301 |
```
|
| 302 |
|
| 303 |
+
*Returns:* `N`.
|
| 304 |
|
| 305 |
#### `array::data` <a id="array.data">[[array.data]]</a>
|
| 306 |
|
| 307 |
``` cpp
|
| 308 |
+
constexpr T* data() noexcept;
|
| 309 |
+
constexpr const T* data() const noexcept;
|
| 310 |
```
|
| 311 |
|
| 312 |
+
*Returns:* A pointer such that `data() == addressof(front())`, and
|
| 313 |
+
\[`data()`, `data() + size()`) is a valid range.
|
| 314 |
|
| 315 |
#### `array::fill` <a id="array.fill">[[array.fill]]</a>
|
| 316 |
|
| 317 |
``` cpp
|
| 318 |
void fill(const T& u);
|
| 319 |
```
|
| 320 |
|
| 321 |
+
*Effects:* As if by `fill_n(begin(), N, u)`.
|
| 322 |
|
| 323 |
#### `array::swap` <a id="array.swap">[[array.swap]]</a>
|
| 324 |
|
| 325 |
``` cpp
|
| 326 |
+
void swap(array& y) noexcept(is_nothrow_swappable_v<T>);
|
| 327 |
```
|
| 328 |
|
| 329 |
+
*Effects:* Equivalent to `swap_ranges(begin(), end(), y.begin())`.
|
| 330 |
|
| 331 |
+
[*Note 1*: Unlike the `swap` function for other containers,
|
| 332 |
+
`array::swap` takes linear time, may exit via an exception, and does not
|
| 333 |
+
cause iterators to become associated with the other
|
| 334 |
+
container. — *end note*]
|
|
|
|
|
|
|
| 335 |
|
| 336 |
#### Zero sized arrays <a id="array.zero">[[array.zero]]</a>
|
| 337 |
|
| 338 |
`array` shall provide support for the special case `N == 0`.
|
| 339 |
|
|
|
|
| 341 |
return value of `data()` is unspecified.
|
| 342 |
|
| 343 |
The effect of calling `front()` or `back()` for a zero-sized array is
|
| 344 |
undefined.
|
| 345 |
|
| 346 |
+
Member function `swap()` shall have a non-throwing exception
|
| 347 |
+
specification.
|
| 348 |
|
| 349 |
#### Tuple interface to class template `array` <a id="array.tuple">[[array.tuple]]</a>
|
| 350 |
|
| 351 |
``` cpp
|
| 352 |
template <class T, size_t N>
|
| 353 |
+
struct tuple_size<array<T, N>> : integral_constant<size_t, N> { };
|
|
|
|
| 354 |
```
|
| 355 |
|
| 356 |
``` cpp
|
| 357 |
tuple_element<I, array<T, N>>::type
|
| 358 |
```
|
|
|
|
| 362 |
*Value:* The type T.
|
| 363 |
|
| 364 |
``` cpp
|
| 365 |
template <size_t I, class T, size_t N>
|
| 366 |
constexpr T& get(array<T, N>& a) noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
template <size_t I, class T, size_t N>
|
| 368 |
constexpr T&& get(array<T, N>&& a) noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 369 |
template <size_t I, class T, size_t N>
|
| 370 |
constexpr const T& get(const array<T, N>& a) noexcept;
|
| 371 |
+
template <size_t I, class T, size_t N>
|
| 372 |
+
constexpr const T&& get(const array<T, N>&& a) noexcept;
|
| 373 |
```
|
| 374 |
|
| 375 |
*Requires:* `I < N`. The program is ill-formed if `I` is out of bounds.
|
| 376 |
|
| 377 |
+
*Returns:* A reference to the `I`th element of `a`, where indexing is
|
| 378 |
+
zero-based.
|
| 379 |
|
| 380 |
### Class template `deque` <a id="deque">[[deque]]</a>
|
| 381 |
|
| 382 |
#### Class template `deque` overview <a id="deque.overview">[[deque.overview]]</a>
|
| 383 |
|
| 384 |
+
A `deque` is a sequence container that supports random access iterators
|
| 385 |
+
([[random.access.iterators]]). In addition, it supports constant time
|
| 386 |
insert and erase operations at the beginning or the end; insert and
|
| 387 |
erase in the middle take linear time. That is, a deque is especially
|
| 388 |
+
optimized for pushing and popping elements at the beginning and end.
|
| 389 |
+
Storage management is handled automatically.
|
| 390 |
|
| 391 |
A `deque` satisfies all of the requirements of a container, of a
|
| 392 |
reversible container (given in tables in [[container.requirements]]),
|
| 393 |
of a sequence container, including the optional sequence container
|
| 394 |
requirements ([[sequence.reqmts]]), and of an allocator-aware container
|
|
|
|
| 401 |
namespace std {
|
| 402 |
template <class T, class Allocator = allocator<T>>
|
| 403 |
class deque {
|
| 404 |
public:
|
| 405 |
// types:
|
| 406 |
+
using value_type = T;
|
| 407 |
+
using allocator_type = Allocator;
|
| 408 |
+
using pointer = typename allocator_traits<Allocator>::pointer;
|
| 409 |
+
using const_pointer = typename allocator_traits<Allocator>::const_pointer;
|
| 410 |
+
using reference = value_type&;
|
| 411 |
+
using const_reference = const value_type&;
|
| 412 |
+
using size_type = implementation-defined; // see [container.requirements]
|
| 413 |
+
using difference_type = implementation-defined; // see [container.requirements]
|
| 414 |
+
using iterator = implementation-defined // type of deque::iterator; // see [container.requirements]
|
| 415 |
+
using const_iterator = implementation-defined // type of deque::const_iterator; // see [container.requirements]
|
| 416 |
+
using reverse_iterator = std::reverse_iterator<iterator>;
|
| 417 |
+
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
| 418 |
|
| 419 |
+
// [deque.cons], construct/copy/destroy
|
| 420 |
deque() : deque(Allocator()) { }
|
| 421 |
explicit deque(const Allocator&);
|
| 422 |
explicit deque(size_type n, const Allocator& = Allocator());
|
| 423 |
deque(size_type n, const T& value, const Allocator& = Allocator());
|
| 424 |
template <class InputIterator>
|
|
|
|
| 429 |
deque(deque&&, const Allocator&);
|
| 430 |
deque(initializer_list<T>, const Allocator& = Allocator());
|
| 431 |
|
| 432 |
~deque();
|
| 433 |
deque& operator=(const deque& x);
|
| 434 |
+
deque& operator=(deque&& x)
|
| 435 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value);
|
| 436 |
deque& operator=(initializer_list<T>);
|
| 437 |
template <class InputIterator>
|
| 438 |
void assign(InputIterator first, InputIterator last);
|
| 439 |
void assign(size_type n, const T& t);
|
| 440 |
void assign(initializer_list<T>);
|
|
|
|
| 453 |
const_iterator cbegin() const noexcept;
|
| 454 |
const_iterator cend() const noexcept;
|
| 455 |
const_reverse_iterator crbegin() const noexcept;
|
| 456 |
const_reverse_iterator crend() const noexcept;
|
| 457 |
|
| 458 |
+
// [deque.capacity], capacity
|
| 459 |
+
bool empty() const noexcept;
|
| 460 |
size_type size() const noexcept;
|
| 461 |
size_type max_size() const noexcept;
|
| 462 |
void resize(size_type sz);
|
| 463 |
void resize(size_type sz, const T& c);
|
| 464 |
void shrink_to_fit();
|
|
|
|
| 465 |
|
| 466 |
// element access:
|
| 467 |
reference operator[](size_type n);
|
| 468 |
const_reference operator[](size_type n) const;
|
| 469 |
reference at(size_type n);
|
|
|
|
| 471 |
reference front();
|
| 472 |
const_reference front() const;
|
| 473 |
reference back();
|
| 474 |
const_reference back() const;
|
| 475 |
|
| 476 |
+
// [deque.modifiers], modifiers
|
| 477 |
+
template <class... Args> reference emplace_front(Args&&... args);
|
| 478 |
+
template <class... Args> reference emplace_back(Args&&... args);
|
| 479 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 480 |
|
| 481 |
void push_front(const T& x);
|
| 482 |
void push_front(T&& x);
|
| 483 |
void push_back(const T& x);
|
|
|
|
| 493 |
void pop_front();
|
| 494 |
void pop_back();
|
| 495 |
|
| 496 |
iterator erase(const_iterator position);
|
| 497 |
iterator erase(const_iterator first, const_iterator last);
|
| 498 |
+
void swap(deque&)
|
| 499 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value);
|
| 500 |
void clear() noexcept;
|
| 501 |
};
|
| 502 |
|
| 503 |
+
template<class InputIterator,
|
| 504 |
+
class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
|
| 505 |
+
deque(InputIterator, InputIterator, Allocator = Allocator())
|
| 506 |
+
-> deque<typename iterator_traits<InputIterator>::value_type, Allocator>;
|
| 507 |
+
|
| 508 |
template <class T, class Allocator>
|
| 509 |
bool operator==(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 510 |
template <class T, class Allocator>
|
| 511 |
bool operator< (const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 512 |
template <class T, class Allocator>
|
|
|
|
| 516 |
template <class T, class Allocator>
|
| 517 |
bool operator>=(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 518 |
template <class T, class Allocator>
|
| 519 |
bool operator<=(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 520 |
|
| 521 |
+
// [deque.special], specialized algorithms
|
| 522 |
template <class T, class Allocator>
|
| 523 |
+
void swap(deque<T, Allocator>& x, deque<T, Allocator>& y)
|
| 524 |
+
noexcept(noexcept(x.swap(y)));
|
| 525 |
}
|
| 526 |
```
|
| 527 |
|
| 528 |
#### `deque` constructors, copy, and assignment <a id="deque.cons">[[deque.cons]]</a>
|
| 529 |
|
|
|
|
| 545 |
*Requires:* `T` shall be `DefaultInsertable` into `*this`.
|
| 546 |
|
| 547 |
*Complexity:* Linear in `n`.
|
| 548 |
|
| 549 |
``` cpp
|
| 550 |
+
deque(size_type n, const T& value, const Allocator& = Allocator());
|
|
|
|
| 551 |
```
|
| 552 |
|
| 553 |
*Effects:* Constructs a `deque` with `n` copies of `value`, using the
|
| 554 |
specified allocator.
|
| 555 |
|
|
|
|
| 557 |
|
| 558 |
*Complexity:* Linear in `n`.
|
| 559 |
|
| 560 |
``` cpp
|
| 561 |
template <class InputIterator>
|
| 562 |
+
deque(InputIterator first, InputIterator last, const Allocator& = Allocator());
|
|
|
|
| 563 |
```
|
| 564 |
|
| 565 |
*Effects:* Constructs a `deque` equal to the range \[`first`, `last`),
|
| 566 |
using the specified allocator.
|
| 567 |
|
|
|
|
| 571 |
|
| 572 |
``` cpp
|
| 573 |
void resize(size_type sz);
|
| 574 |
```
|
| 575 |
|
| 576 |
+
*Effects:* If `sz < size()`, erases the last `size() - sz` elements from
|
| 577 |
+
the sequence. Otherwise, appends `sz - size()` default-inserted elements
|
| 578 |
+
to the sequence.
|
| 579 |
|
| 580 |
*Requires:* `T` shall be `MoveInsertable` and `DefaultInsertable` into
|
| 581 |
`*this`.
|
| 582 |
|
| 583 |
``` cpp
|
| 584 |
void resize(size_type sz, const T& c);
|
| 585 |
```
|
| 586 |
|
| 587 |
+
*Effects:* If `sz < size()`, erases the last `size() - sz` elements from
|
| 588 |
+
the sequence. Otherwise, appends `sz - size()` copies of `c` to the
|
| 589 |
+
sequence.
|
| 590 |
|
| 591 |
*Requires:* `T` shall be `CopyInsertable` into `*this`.
|
| 592 |
|
| 593 |
``` cpp
|
| 594 |
void shrink_to_fit();
|
| 595 |
```
|
| 596 |
|
| 597 |
*Requires:* `T` shall be `MoveInsertable` into `*this`.
|
| 598 |
|
| 599 |
+
*Effects:* `shrink_to_fit` is a non-binding request to reduce memory use
|
| 600 |
+
but does not change the size of the sequence.
|
| 601 |
+
|
| 602 |
+
[*Note 1*: The request is non-binding to allow latitude for
|
| 603 |
+
implementation-specific optimizations. — *end note*]
|
| 604 |
+
|
| 605 |
+
If an exception is thrown other than by the move constructor of a
|
| 606 |
+
non-`CopyInsertable` `T` there are no effects.
|
| 607 |
+
|
| 608 |
*Complexity:* Linear in the size of the sequence.
|
| 609 |
|
| 610 |
+
*Remarks:* `shrink_to_fit` invalidates all the references, pointers, and
|
| 611 |
+
iterators referring to the elements in the sequence as well as the
|
| 612 |
+
past-the-end iterator.
|
| 613 |
|
| 614 |
#### `deque` modifiers <a id="deque.modifiers">[[deque.modifiers]]</a>
|
| 615 |
|
| 616 |
``` cpp
|
| 617 |
iterator insert(const_iterator position, const T& x);
|
|
|
|
| 620 |
template <class InputIterator>
|
| 621 |
iterator insert(const_iterator position,
|
| 622 |
InputIterator first, InputIterator last);
|
| 623 |
iterator insert(const_iterator position, initializer_list<T>);
|
| 624 |
|
| 625 |
+
template <class... Args> reference emplace_front(Args&&... args);
|
| 626 |
+
template <class... Args> reference emplace_back(Args&&... args);
|
| 627 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 628 |
void push_front(const T& x);
|
| 629 |
void push_front(T&& x);
|
| 630 |
void push_back(const T& x);
|
| 631 |
void push_back(T&& x);
|
|
|
|
| 650 |
constructor of `T`.
|
| 651 |
|
| 652 |
``` cpp
|
| 653 |
iterator erase(const_iterator position);
|
| 654 |
iterator erase(const_iterator first, const_iterator last);
|
| 655 |
+
void pop_front();
|
| 656 |
+
void pop_back();
|
| 657 |
```
|
| 658 |
|
| 659 |
*Effects:* An erase operation that erases the last element of a deque
|
| 660 |
invalidates only the past-the-end iterator and all iterators and
|
| 661 |
references to the erased elements. An erase operation that erases the
|
| 662 |
+
first element of a deque but not the last element invalidates only
|
| 663 |
+
iterators and references to the erased elements. An erase operation that
|
| 664 |
+
erases neither the first element nor the last element of a deque
|
| 665 |
+
invalidates the past-the-end iterator and all iterators and references
|
| 666 |
+
to all the elements of the deque.
|
| 667 |
|
| 668 |
+
[*Note 1*: `pop_front` and `pop_back` are erase
|
| 669 |
+
operations. — *end note*]
|
| 670 |
+
|
| 671 |
+
*Complexity:* The number of calls to the destructor of `T` is the same
|
| 672 |
+
as the number of elements erased, but the number of calls to the
|
| 673 |
+
assignment operator of `T` is no more than the lesser of the number of
|
| 674 |
+
elements before the erased elements and the number of elements after the
|
| 675 |
+
erased elements.
|
| 676 |
|
| 677 |
*Throws:* Nothing unless an exception is thrown by the copy constructor,
|
| 678 |
move constructor, assignment operator, or move assignment operator of
|
| 679 |
`T`.
|
| 680 |
|
| 681 |
#### `deque` specialized algorithms <a id="deque.special">[[deque.special]]</a>
|
| 682 |
|
| 683 |
``` cpp
|
| 684 |
template <class T, class Allocator>
|
| 685 |
+
void swap(deque<T, Allocator>& x, deque<T, Allocator>& y)
|
| 686 |
+
noexcept(noexcept(x.swap(y)));
|
| 687 |
```
|
| 688 |
|
| 689 |
+
*Effects:* As if by `x.swap(y)`.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 690 |
|
| 691 |
### Class template `forward_list` <a id="forwardlist">[[forwardlist]]</a>
|
| 692 |
|
| 693 |
#### Class template `forward_list` overview <a id="forwardlist.overview">[[forwardlist.overview]]</a>
|
| 694 |
|
| 695 |
A `forward_list` is a container that supports forward iterators and
|
| 696 |
allows constant time insert and erase operations anywhere within the
|
| 697 |
sequence, with storage management handled automatically. Fast random
|
| 698 |
+
access to list elements is not supported.
|
| 699 |
+
|
| 700 |
+
[*Note 1*: It is intended that `forward_list` have zero space or time
|
| 701 |
+
overhead relative to a hand-written C-style singly linked list. Features
|
| 702 |
+
that would conflict with that goal have been omitted. — *end note*]
|
| 703 |
|
| 704 |
A `forward_list` satisfies all of the requirements of a container
|
| 705 |
(Table [[tab:containers.container.requirements]]), except that the
|
| 706 |
`size()` member function is not provided and `operator==` has linear
|
| 707 |
complexity. A `forward_list` also satisfies all of the requirements for
|
|
|
|
| 711 |
optional container requirements (Table
|
| 712 |
[[tab:containers.sequence.optional]]). Descriptions are provided here
|
| 713 |
only for operations on `forward_list` that are not described in that
|
| 714 |
table or for operations where there is additional semantic information.
|
| 715 |
|
| 716 |
+
[*Note 2*: Modifying any list requires access to the element preceding
|
| 717 |
+
the first element of interest, but in a `forward_list` there is no
|
| 718 |
+
constant-time way to access a preceding element. For this reason, ranges
|
| 719 |
+
that are modified, such as those supplied to `erase` and `splice`, must
|
| 720 |
+
be open at the beginning. — *end note*]
|
| 721 |
|
| 722 |
``` cpp
|
| 723 |
namespace std {
|
| 724 |
template <class T, class Allocator = allocator<T>>
|
| 725 |
class forward_list {
|
| 726 |
public:
|
| 727 |
// types:
|
| 728 |
+
using value_type = T;
|
| 729 |
+
using allocator_type = Allocator;
|
| 730 |
+
using pointer = typename allocator_traits<Allocator>::pointer;
|
| 731 |
+
using const_pointer = typename allocator_traits<Allocator>::const_pointer;
|
| 732 |
+
using reference = value_type&;
|
| 733 |
+
using const_reference = const value_type&;
|
| 734 |
+
using size_type = implementation-defined; // see [container.requirements]
|
| 735 |
+
using difference_type = implementation-defined; // see [container.requirements]
|
| 736 |
+
using iterator = implementation-defined // type of forward_list::iterator; // see [container.requirements]
|
| 737 |
+
using const_iterator = implementation-defined // type of forward_list::const_iterator; // see [container.requirements]
|
| 738 |
|
| 739 |
+
// [forwardlist.cons], construct/copy/destroy
|
| 740 |
forward_list() : forward_list(Allocator()) { }
|
| 741 |
explicit forward_list(const Allocator&);
|
| 742 |
explicit forward_list(size_type n, const Allocator& = Allocator());
|
| 743 |
forward_list(size_type n, const T& value,
|
| 744 |
const Allocator& = Allocator());
|
|
|
|
| 750 |
forward_list(const forward_list& x, const Allocator&);
|
| 751 |
forward_list(forward_list&& x, const Allocator&);
|
| 752 |
forward_list(initializer_list<T>, const Allocator& = Allocator());
|
| 753 |
~forward_list();
|
| 754 |
forward_list& operator=(const forward_list& x);
|
| 755 |
+
forward_list& operator=(forward_list&& x)
|
| 756 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value);
|
| 757 |
forward_list& operator=(initializer_list<T>);
|
| 758 |
template <class InputIterator>
|
| 759 |
void assign(InputIterator first, InputIterator last);
|
| 760 |
void assign(size_type n, const T& t);
|
| 761 |
void assign(initializer_list<T>);
|
| 762 |
allocator_type get_allocator() const noexcept;
|
| 763 |
|
| 764 |
+
// [forwardlist.iter], iterators
|
| 765 |
iterator before_begin() noexcept;
|
| 766 |
const_iterator before_begin() const noexcept;
|
| 767 |
iterator begin() noexcept;
|
| 768 |
const_iterator begin() const noexcept;
|
| 769 |
iterator end() noexcept;
|
|
|
|
| 775 |
|
| 776 |
// capacity:
|
| 777 |
bool empty() const noexcept;
|
| 778 |
size_type max_size() const noexcept;
|
| 779 |
|
| 780 |
+
// [forwardlist.access], element access
|
| 781 |
reference front();
|
| 782 |
const_reference front() const;
|
| 783 |
|
| 784 |
+
// [forwardlist.modifiers], modifiers
|
| 785 |
+
template <class... Args> reference emplace_front(Args&&... args);
|
| 786 |
void push_front(const T& x);
|
| 787 |
void push_front(T&& x);
|
| 788 |
void pop_front();
|
| 789 |
|
| 790 |
template <class... Args> iterator emplace_after(const_iterator position, Args&&... args);
|
|
|
|
| 796 |
iterator insert_after(const_iterator position, InputIterator first, InputIterator last);
|
| 797 |
iterator insert_after(const_iterator position, initializer_list<T> il);
|
| 798 |
|
| 799 |
iterator erase_after(const_iterator position);
|
| 800 |
iterator erase_after(const_iterator position, const_iterator last);
|
| 801 |
+
void swap(forward_list&)
|
| 802 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value);
|
| 803 |
|
| 804 |
void resize(size_type sz);
|
| 805 |
void resize(size_type sz, const value_type& c);
|
| 806 |
void clear() noexcept;
|
| 807 |
|
| 808 |
+
// [forwardlist.ops], forward_list operations
|
| 809 |
void splice_after(const_iterator position, forward_list& x);
|
| 810 |
void splice_after(const_iterator position, forward_list&& x);
|
| 811 |
void splice_after(const_iterator position, forward_list& x,
|
| 812 |
const_iterator i);
|
| 813 |
void splice_after(const_iterator position, forward_list&& x,
|
|
|
|
| 832 |
template <class Compare> void sort(Compare comp);
|
| 833 |
|
| 834 |
void reverse() noexcept;
|
| 835 |
};
|
| 836 |
|
| 837 |
+
template<class InputIterator,
|
| 838 |
+
class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
|
| 839 |
+
forward_list(InputIterator, InputIterator, Allocator = Allocator())
|
| 840 |
+
-> forward_list<typename iterator_traits<InputIterator>::value_type, Allocator>;
|
| 841 |
+
|
| 842 |
template <class T, class Allocator>
|
| 843 |
bool operator==(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 844 |
template <class T, class Allocator>
|
| 845 |
bool operator< (const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 846 |
template <class T, class Allocator>
|
|
|
|
| 850 |
template <class T, class Allocator>
|
| 851 |
bool operator>=(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 852 |
template <class T, class Allocator>
|
| 853 |
bool operator<=(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 854 |
|
| 855 |
+
// [forwardlist.spec], specialized algorithms
|
| 856 |
template <class T, class Allocator>
|
| 857 |
+
void swap(forward_list<T, Allocator>& x, forward_list<T, Allocator>& y)
|
| 858 |
+
noexcept(noexcept(x.swap(y)));
|
| 859 |
}
|
| 860 |
```
|
| 861 |
|
| 862 |
+
An incomplete type `T` may be used when instantiating `forward_list` if
|
| 863 |
+
the allocator satisfies the allocator completeness requirements (
|
| 864 |
+
[[allocator.requirements.completeness]]). `T` shall be complete before
|
| 865 |
+
any member of the resulting specialization of `forward_list` is
|
| 866 |
+
referenced.
|
| 867 |
+
|
| 868 |
#### `forward_list` constructors, copy, assignment <a id="forwardlist.cons">[[forwardlist.cons]]</a>
|
| 869 |
|
| 870 |
``` cpp
|
| 871 |
explicit forward_list(const Allocator&);
|
| 872 |
```
|
|
|
|
| 943 |
to the copy or move constructor of `T` is exactly equal to `n`. Erasing
|
| 944 |
`n` elements from a `forward_list` is linear in `n` and the number of
|
| 945 |
calls to the destructor of type `T` is exactly equal to `n`.
|
| 946 |
|
| 947 |
``` cpp
|
| 948 |
+
template <class... Args> reference emplace_front(Args&&... args);
|
| 949 |
```
|
| 950 |
|
| 951 |
*Effects:* Inserts an object of type `value_type` constructed with
|
| 952 |
`value_type(std::forward<Args>(args)...)` at the beginning of the list.
|
| 953 |
|
|
|
|
| 960 |
|
| 961 |
``` cpp
|
| 962 |
void pop_front();
|
| 963 |
```
|
| 964 |
|
| 965 |
+
*Effects:* As if by `erase_after(before_begin())`.
|
| 966 |
|
| 967 |
``` cpp
|
| 968 |
iterator insert_after(const_iterator position, const T& x);
|
| 969 |
iterator insert_after(const_iterator position, T&& x);
|
| 970 |
```
|
|
|
|
| 1067 |
void resize(size_type sz, const value_type& c);
|
| 1068 |
```
|
| 1069 |
|
| 1070 |
*Effects:* If `sz < distance(begin(), end())`, erases the last
|
| 1071 |
`distance(begin(), end()) - sz` elements from the list. Otherwise,
|
| 1072 |
+
inserts `sz - distance(begin(), end())` copies of `c` at the end of the
|
| 1073 |
+
list.
|
|
|
|
|
|
|
| 1074 |
|
| 1075 |
*Requires:* `T` shall be `CopyInsertable` into `*this`.
|
| 1076 |
|
| 1077 |
``` cpp
|
| 1078 |
void clear() noexcept;
|
|
|
|
| 1099 |
the moved elements will continue to refer to their elements, but they
|
| 1100 |
now behave as iterators into `*this`, not into `x`.
|
| 1101 |
|
| 1102 |
*Throws:* Nothing.
|
| 1103 |
|
| 1104 |
+
*Complexity:* 𝑂(`distance(x.begin(), x.end())`)
|
| 1105 |
|
| 1106 |
``` cpp
|
| 1107 |
void splice_after(const_iterator position, forward_list& x, const_iterator i);
|
| 1108 |
void splice_after(const_iterator position, forward_list&& x, const_iterator i);
|
| 1109 |
```
|
|
|
|
| 1142 |
the moved elements of `x` now refer to those same elements but as
|
| 1143 |
members of `*this`. Iterators referring to the moved elements will
|
| 1144 |
continue to refer to their elements, but they now behave as iterators
|
| 1145 |
into `*this`, not into `x`.
|
| 1146 |
|
| 1147 |
+
*Complexity:* 𝑂(`distance(first, last)`)
|
| 1148 |
|
| 1149 |
``` cpp
|
| 1150 |
void remove(const T& value);
|
| 1151 |
template <class Predicate> void remove_if(Predicate pred);
|
| 1152 |
```
|
| 1153 |
|
| 1154 |
*Effects:* Erases all the elements in the list referred by a list
|
| 1155 |
iterator `i` for which the following conditions hold: `*i == value` (for
|
| 1156 |
+
`remove()`), `pred(*i)` is `true` (for `remove_if()`). Invalidates only
|
| 1157 |
the iterators and references to the erased elements.
|
| 1158 |
|
| 1159 |
*Throws:* Nothing unless an exception is thrown by the equality
|
| 1160 |
comparison or the predicate.
|
| 1161 |
|
|
|
|
| 1201 |
but as members of `*this`. Iterators referring to the moved elements
|
| 1202 |
will continue to refer to their elements, but they now behave as
|
| 1203 |
iterators into `*this`, not into `x`.
|
| 1204 |
|
| 1205 |
*Remarks:* Stable ([[algorithm.stable]]). The behavior is undefined if
|
| 1206 |
+
`get_allocator() != x.get_allocator()`.
|
| 1207 |
|
| 1208 |
*Complexity:* At most
|
| 1209 |
`distance(begin(), end()) + distance(x.begin(), x.end()) - 1`
|
| 1210 |
comparisons.
|
| 1211 |
|
|
|
|
| 1217 |
*Requires:* `operator<` (for the version with no arguments) or `comp`
|
| 1218 |
(for the version with a comparison argument) defines a strict weak
|
| 1219 |
ordering ([[alg.sorting]]).
|
| 1220 |
|
| 1221 |
*Effects:* Sorts the list according to the `operator<` or the `comp`
|
| 1222 |
+
function object. If an exception is thrown, the order of the elements in
|
| 1223 |
`*this` is unspecified. Does not affect the validity of iterators and
|
| 1224 |
references.
|
| 1225 |
|
| 1226 |
*Remarks:* Stable ([[algorithm.stable]]).
|
| 1227 |
|
|
|
|
| 1239 |
|
| 1240 |
#### `forward_list` specialized algorithms <a id="forwardlist.spec">[[forwardlist.spec]]</a>
|
| 1241 |
|
| 1242 |
``` cpp
|
| 1243 |
template <class T, class Allocator>
|
| 1244 |
+
void swap(forward_list<T, Allocator>& x, forward_list<T, Allocator>& y)
|
| 1245 |
+
noexcept(noexcept(x.swap(y)));
|
| 1246 |
```
|
| 1247 |
|
| 1248 |
+
*Effects:* As if by `x.swap(y)`.
|
| 1249 |
|
| 1250 |
### Class template `list` <a id="list">[[list]]</a>
|
| 1251 |
|
| 1252 |
#### Class template `list` overview <a id="list.overview">[[list.overview]]</a>
|
| 1253 |
|
|
|
|
| 1273 |
namespace std {
|
| 1274 |
template <class T, class Allocator = allocator<T>>
|
| 1275 |
class list {
|
| 1276 |
public:
|
| 1277 |
// types:
|
| 1278 |
+
using value_type = T;
|
| 1279 |
+
using allocator_type = Allocator;
|
| 1280 |
+
using pointer = typename allocator_traits<Allocator>::pointer;
|
| 1281 |
+
using const_pointer = typename allocator_traits<Allocator>::const_pointer;
|
| 1282 |
+
using reference = value_type&;
|
| 1283 |
+
using const_reference = const value_type&;
|
| 1284 |
+
using size_type = implementation-defined; // see [container.requirements]
|
| 1285 |
+
using difference_type = implementation-defined; // see [container.requirements]
|
| 1286 |
+
using iterator = implementation-defined // type of list::iterator; // see [container.requirements]
|
| 1287 |
+
using const_iterator = implementation-defined // type of list::const_iterator; // see [container.requirements]
|
| 1288 |
+
using reverse_iterator = std::reverse_iterator<iterator>;
|
| 1289 |
+
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
| 1290 |
|
| 1291 |
+
// [list.cons], construct/copy/destroy
|
| 1292 |
list() : list(Allocator()) { }
|
| 1293 |
explicit list(const Allocator&);
|
| 1294 |
explicit list(size_type n, const Allocator& = Allocator());
|
| 1295 |
list(size_type n, const T& value, const Allocator& = Allocator());
|
| 1296 |
template <class InputIterator>
|
|
|
|
| 1300 |
list(const list&, const Allocator&);
|
| 1301 |
list(list&&, const Allocator&);
|
| 1302 |
list(initializer_list<T>, const Allocator& = Allocator());
|
| 1303 |
~list();
|
| 1304 |
list& operator=(const list& x);
|
| 1305 |
+
list& operator=(list&& x)
|
| 1306 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value);
|
| 1307 |
list& operator=(initializer_list<T>);
|
| 1308 |
template <class InputIterator>
|
| 1309 |
void assign(InputIterator first, InputIterator last);
|
| 1310 |
void assign(size_type n, const T& t);
|
| 1311 |
void assign(initializer_list<T>);
|
|
|
|
| 1324 |
const_iterator cbegin() const noexcept;
|
| 1325 |
const_iterator cend() const noexcept;
|
| 1326 |
const_reverse_iterator crbegin() const noexcept;
|
| 1327 |
const_reverse_iterator crend() const noexcept;
|
| 1328 |
|
| 1329 |
+
// [list.capacity], capacity
|
| 1330 |
bool empty() const noexcept;
|
| 1331 |
size_type size() const noexcept;
|
| 1332 |
size_type max_size() const noexcept;
|
| 1333 |
void resize(size_type sz);
|
| 1334 |
void resize(size_type sz, const T& c);
|
|
|
|
| 1337 |
reference front();
|
| 1338 |
const_reference front() const;
|
| 1339 |
reference back();
|
| 1340 |
const_reference back() const;
|
| 1341 |
|
| 1342 |
+
// [list.modifiers], modifiers
|
| 1343 |
+
template <class... Args> reference emplace_front(Args&&... args);
|
| 1344 |
+
template <class... Args> reference emplace_back(Args&&... args);
|
|
|
|
| 1345 |
void push_front(const T& x);
|
| 1346 |
void push_front(T&& x);
|
| 1347 |
+
void pop_front();
|
| 1348 |
void push_back(const T& x);
|
| 1349 |
void push_back(T&& x);
|
| 1350 |
void pop_back();
|
| 1351 |
|
| 1352 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
|
|
|
| 1358 |
InputIterator last);
|
| 1359 |
iterator insert(const_iterator position, initializer_list<T> il);
|
| 1360 |
|
| 1361 |
iterator erase(const_iterator position);
|
| 1362 |
iterator erase(const_iterator position, const_iterator last);
|
| 1363 |
+
void swap(list&)
|
| 1364 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value);
|
| 1365 |
void clear() noexcept;
|
| 1366 |
|
| 1367 |
+
// [list.ops], list operations
|
| 1368 |
void splice(const_iterator position, list& x);
|
| 1369 |
void splice(const_iterator position, list&& x);
|
| 1370 |
void splice(const_iterator position, list& x, const_iterator i);
|
| 1371 |
void splice(const_iterator position, list&& x, const_iterator i);
|
| 1372 |
void splice(const_iterator position, list& x,
|
|
|
|
| 1390 |
template <class Compare> void sort(Compare comp);
|
| 1391 |
|
| 1392 |
void reverse() noexcept;
|
| 1393 |
};
|
| 1394 |
|
| 1395 |
+
template<class InputIterator,
|
| 1396 |
+
class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
|
| 1397 |
+
list(InputIterator, InputIterator, Allocator = Allocator())
|
| 1398 |
+
-> list<typename iterator_traits<InputIterator>::value_type, Allocator>;
|
| 1399 |
+
|
| 1400 |
template <class T, class Allocator>
|
| 1401 |
bool operator==(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 1402 |
template <class T, class Allocator>
|
| 1403 |
bool operator< (const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 1404 |
template <class T, class Allocator>
|
|
|
|
| 1408 |
template <class T, class Allocator>
|
| 1409 |
bool operator>=(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 1410 |
template <class T, class Allocator>
|
| 1411 |
bool operator<=(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 1412 |
|
| 1413 |
+
// [list.special], specialized algorithms
|
| 1414 |
template <class T, class Allocator>
|
| 1415 |
+
void swap(list<T, Allocator>& x, list<T, Allocator>& y)
|
| 1416 |
+
noexcept(noexcept(x.swap(y)));
|
| 1417 |
}
|
| 1418 |
```
|
| 1419 |
|
| 1420 |
+
An incomplete type `T` may be used when instantiating `list` if the
|
| 1421 |
+
allocator satisfies the allocator completeness requirements (
|
| 1422 |
+
[[allocator.requirements.completeness]]). `T` shall be complete before
|
| 1423 |
+
any member of the resulting specialization of `list` is referenced.
|
| 1424 |
+
|
| 1425 |
#### `list` constructors, copy, and assignment <a id="list.cons">[[list.cons]]</a>
|
| 1426 |
|
| 1427 |
``` cpp
|
| 1428 |
explicit list(const Allocator&);
|
| 1429 |
```
|
|
|
|
| 1442 |
*Requires:* `T` shall be `DefaultInsertable` into `*this`.
|
| 1443 |
|
| 1444 |
*Complexity:* Linear in `n`.
|
| 1445 |
|
| 1446 |
``` cpp
|
| 1447 |
+
list(size_type n, const T& value, const Allocator& = Allocator());
|
|
|
|
| 1448 |
```
|
| 1449 |
|
| 1450 |
*Effects:* Constructs a `list` with `n` copies of `value`, using the
|
| 1451 |
specified allocator.
|
| 1452 |
|
|
|
|
| 1454 |
|
| 1455 |
*Complexity:* Linear in `n`.
|
| 1456 |
|
| 1457 |
``` cpp
|
| 1458 |
template <class InputIterator>
|
| 1459 |
+
list(InputIterator first, InputIterator last, const Allocator& = Allocator());
|
|
|
|
| 1460 |
```
|
| 1461 |
|
| 1462 |
*Effects:* Constructs a `list` equal to the range \[`first`, `last`).
|
| 1463 |
|
| 1464 |
*Complexity:* Linear in `distance(first, last)`.
|
|
|
|
| 1468 |
``` cpp
|
| 1469 |
void resize(size_type sz);
|
| 1470 |
```
|
| 1471 |
|
| 1472 |
*Effects:* If `size() < sz`, appends `sz - size()` default-inserted
|
| 1473 |
+
elements to the sequence. If `sz <= size()`, equivalent to:
|
| 1474 |
|
| 1475 |
``` cpp
|
| 1476 |
list<T>::iterator it = begin();
|
| 1477 |
advance(it, sz);
|
| 1478 |
erase(it, end());
|
|
|
|
| 1482 |
|
| 1483 |
``` cpp
|
| 1484 |
void resize(size_type sz, const T& c);
|
| 1485 |
```
|
| 1486 |
|
| 1487 |
+
*Effects:* As if by:
|
| 1488 |
|
| 1489 |
``` cpp
|
| 1490 |
if (sz > size())
|
| 1491 |
insert(end(), sz-size(), c);
|
| 1492 |
else if (sz < size()) {
|
|
|
|
| 1509 |
template <class InputIterator>
|
| 1510 |
iterator insert(const_iterator position, InputIterator first,
|
| 1511 |
InputIterator last);
|
| 1512 |
iterator insert(const_iterator position, initializer_list<T>);
|
| 1513 |
|
| 1514 |
+
template <class... Args> reference emplace_front(Args&&... args);
|
| 1515 |
+
template <class... Args> reference emplace_back(Args&&... args);
|
| 1516 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 1517 |
void push_front(const T& x);
|
| 1518 |
void push_front(T&& x);
|
| 1519 |
void push_back(const T& x);
|
| 1520 |
void push_back(T&& x);
|
|
|
|
| 1578 |
``` cpp
|
| 1579 |
void splice(const_iterator position, list& x, const_iterator i);
|
| 1580 |
void splice(const_iterator position, list&& x, const_iterator i);
|
| 1581 |
```
|
| 1582 |
|
| 1583 |
+
*Requires:* `i` is a valid dereferenceable iterator of `x`.
|
| 1584 |
+
|
| 1585 |
*Effects:* Inserts an element pointed to by `i` from list `x` before
|
| 1586 |
`position` and removes the element from `x`. The result is unchanged if
|
| 1587 |
`position == i` or `position == ++i`. Pointers and references to `*i`
|
| 1588 |
continue to refer to this same element but as a member of `*this`.
|
| 1589 |
Iterators to `*i` (including `i` itself) continue to refer to the same
|
| 1590 |
element, but now behave as iterators into `*this`, not into `x`.
|
| 1591 |
|
|
|
|
|
|
|
| 1592 |
*Throws:* Nothing.
|
| 1593 |
|
| 1594 |
*Complexity:* Constant time.
|
| 1595 |
|
| 1596 |
``` cpp
|
|
|
|
| 1598 |
const_iterator last);
|
| 1599 |
void splice(const_iterator position, list&& x, const_iterator first,
|
| 1600 |
const_iterator last);
|
| 1601 |
```
|
| 1602 |
|
| 1603 |
+
*Requires:* `[first, last)` is a valid range in `x`. The program has
|
| 1604 |
+
undefined behavior if `position` is an iterator in the range \[`first`,
|
| 1605 |
+
`last`).
|
| 1606 |
+
|
| 1607 |
*Effects:* Inserts elements in the range \[`first`, `last`) before
|
| 1608 |
+
`position` and removes the elements from `x`. Pointers and references to
|
| 1609 |
+
the moved elements of `x` now refer to those same elements but as
|
| 1610 |
+
members of `*this`. Iterators referring to the moved elements will
|
| 1611 |
+
continue to refer to their elements, but they now behave as iterators
|
| 1612 |
+
into `*this`, not into `x`.
|
|
|
|
|
|
|
|
|
|
| 1613 |
|
| 1614 |
*Throws:* Nothing.
|
| 1615 |
|
| 1616 |
*Complexity:* Constant time if `&x == this`; otherwise, linear time.
|
| 1617 |
|
|
|
|
| 1666 |
*Effects:* If `(&x == this)` does nothing; otherwise, merges the two
|
| 1667 |
sorted ranges `[begin(), end())` and `[x.begin(), x.end())`. The result
|
| 1668 |
is a range in which the elements will be sorted in non-decreasing order
|
| 1669 |
according to the ordering defined by `comp`; that is, for every iterator
|
| 1670 |
`i`, in the range other than the first, the condition
|
| 1671 |
+
`comp(*i, *(i - 1))` will be `false`. Pointers and references to the
|
| 1672 |
+
moved elements of `x` now refer to those same elements but as members of
|
| 1673 |
`*this`. Iterators referring to the moved elements will continue to
|
| 1674 |
refer to their elements, but they now behave as iterators into `*this`,
|
| 1675 |
not into `x`.
|
| 1676 |
|
| 1677 |
*Remarks:* Stable ([[algorithm.stable]]). If `(&x != this)` the range
|
| 1678 |
`[x.begin(), x.end())` is empty after the merge. No elements are copied
|
| 1679 |
by this operation. The behavior is undefined if
|
| 1680 |
+
`get_allocator() != x.get_allocator()`.
|
| 1681 |
|
| 1682 |
*Complexity:* At most `size() + x.size() - 1` applications of `comp` if
|
| 1683 |
`(&x != this)`; otherwise, no applications of `comp` are performed. If
|
| 1684 |
an exception is thrown other than by a comparison there are no effects.
|
| 1685 |
|
|
|
|
| 1699 |
|
| 1700 |
*Requires:* `operator<` (for the first version) or `comp` (for the
|
| 1701 |
second version) shall define a strict weak ordering ([[alg.sorting]]).
|
| 1702 |
|
| 1703 |
*Effects:* Sorts the list according to the `operator<` or a `Compare`
|
| 1704 |
+
function object. If an exception is thrown, the order of the elements in
|
| 1705 |
+
`*this` is unspecified. Does not affect the validity of iterators and
|
| 1706 |
references.
|
| 1707 |
|
| 1708 |
*Remarks:* Stable ([[algorithm.stable]]).
|
| 1709 |
|
| 1710 |
+
*Complexity:* Approximately N log N comparisons, where `N == size()`.
|
| 1711 |
|
| 1712 |
#### `list` specialized algorithms <a id="list.special">[[list.special]]</a>
|
| 1713 |
|
| 1714 |
``` cpp
|
| 1715 |
template <class T, class Allocator>
|
| 1716 |
+
void swap(list<T, Allocator>& x, list<T, Allocator>& y)
|
| 1717 |
+
noexcept(noexcept(x.swap(y)));
|
| 1718 |
```
|
| 1719 |
|
| 1720 |
+
*Effects:* As if by `x.swap(y)`.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1721 |
|
| 1722 |
### Class template `vector` <a id="vector">[[vector]]</a>
|
| 1723 |
|
| 1724 |
#### Class template `vector` overview <a id="vector.overview">[[vector.overview]]</a>
|
| 1725 |
|
| 1726 |
+
A `vector` is a sequence container that supports (amortized) constant
|
| 1727 |
+
time insert and erase operations at the end; insert and erase in the
|
| 1728 |
+
middle take linear time. Storage management is handled automatically,
|
| 1729 |
+
though hints can be given to improve efficiency.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1730 |
|
| 1731 |
A `vector` satisfies all of the requirements of a container and of a
|
| 1732 |
reversible container (given in two tables in
|
| 1733 |
[[container.requirements]]), of a sequence container, including most of
|
| 1734 |
+
the optional sequence container requirements ([[sequence.reqmts]]), of
|
| 1735 |
+
an allocator-aware container (Table [[tab:containers.allocatoraware]]),
|
| 1736 |
+
and, for an element type other than `bool`, of a contiguous container (
|
| 1737 |
+
[[container.requirements.general]]). The exceptions are the
|
| 1738 |
+
`push_front`, `pop_front`, and `emplace_front` member functions, which
|
| 1739 |
+
are not provided. Descriptions are provided here only for operations on
|
| 1740 |
+
`vector` that are not described in one of these tables or for operations
|
| 1741 |
+
where there is additional semantic information.
|
| 1742 |
|
| 1743 |
``` cpp
|
| 1744 |
namespace std {
|
| 1745 |
template <class T, class Allocator = allocator<T>>
|
| 1746 |
class vector {
|
| 1747 |
public:
|
| 1748 |
// types:
|
| 1749 |
+
using value_type = T;
|
| 1750 |
+
using allocator_type = Allocator;
|
| 1751 |
+
using pointer = typename allocator_traits<Allocator>::pointer;
|
| 1752 |
+
using const_pointer = typename allocator_traits<Allocator>::const_pointer;
|
| 1753 |
+
using reference = value_type&;
|
| 1754 |
+
using const_reference = const value_type&;
|
| 1755 |
+
using size_type = implementation-defined; // see [container.requirements]
|
| 1756 |
+
using difference_type = implementation-defined; // see [container.requirements]
|
| 1757 |
+
using iterator = implementation-defined // type of vector::iterator; // see [container.requirements]
|
| 1758 |
+
using const_iterator = implementation-defined // type of vector::const_iterator; // see [container.requirements]
|
| 1759 |
+
using reverse_iterator = std::reverse_iterator<iterator>;
|
| 1760 |
+
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
| 1761 |
|
| 1762 |
+
// [vector.cons], construct/copy/destroy
|
| 1763 |
+
vector() noexcept(noexcept(Allocator())) : vector(Allocator()) { }
|
| 1764 |
+
explicit vector(const Allocator&) noexcept;
|
| 1765 |
explicit vector(size_type n, const Allocator& = Allocator());
|
| 1766 |
vector(size_type n, const T& value, const Allocator& = Allocator());
|
| 1767 |
template <class InputIterator>
|
| 1768 |
+
vector(InputIterator first, InputIterator last, const Allocator& = Allocator());
|
|
|
|
| 1769 |
vector(const vector& x);
|
| 1770 |
+
vector(vector&&) noexcept;
|
| 1771 |
vector(const vector&, const Allocator&);
|
| 1772 |
vector(vector&&, const Allocator&);
|
| 1773 |
vector(initializer_list<T>, const Allocator& = Allocator());
|
| 1774 |
~vector();
|
| 1775 |
vector& operator=(const vector& x);
|
| 1776 |
+
vector& operator=(vector&& x)
|
| 1777 |
+
noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
|
| 1778 |
+
allocator_traits<Allocator>::is_always_equal::value);
|
| 1779 |
vector& operator=(initializer_list<T>);
|
| 1780 |
template <class InputIterator>
|
| 1781 |
void assign(InputIterator first, InputIterator last);
|
| 1782 |
void assign(size_type n, const T& u);
|
| 1783 |
void assign(initializer_list<T>);
|
|
|
|
| 1796 |
const_iterator cbegin() const noexcept;
|
| 1797 |
const_iterator cend() const noexcept;
|
| 1798 |
const_reverse_iterator crbegin() const noexcept;
|
| 1799 |
const_reverse_iterator crend() const noexcept;
|
| 1800 |
|
| 1801 |
+
// [vector.capacity], capacity
|
| 1802 |
+
bool empty() const noexcept;
|
| 1803 |
size_type size() const noexcept;
|
| 1804 |
size_type max_size() const noexcept;
|
| 1805 |
+
size_type capacity() const noexcept;
|
| 1806 |
void resize(size_type sz);
|
| 1807 |
void resize(size_type sz, const T& c);
|
|
|
|
|
|
|
| 1808 |
void reserve(size_type n);
|
| 1809 |
void shrink_to_fit();
|
| 1810 |
|
| 1811 |
// element access:
|
| 1812 |
reference operator[](size_type n);
|
|
|
|
| 1820 |
|
| 1821 |
// [vector.data], data access
|
| 1822 |
T* data() noexcept;
|
| 1823 |
const T* data() const noexcept;
|
| 1824 |
|
| 1825 |
+
// [vector.modifiers], modifiers
|
| 1826 |
+
template <class... Args> reference emplace_back(Args&&... args);
|
| 1827 |
void push_back(const T& x);
|
| 1828 |
void push_back(T&& x);
|
| 1829 |
void pop_back();
|
| 1830 |
|
| 1831 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 1832 |
iterator insert(const_iterator position, const T& x);
|
| 1833 |
iterator insert(const_iterator position, T&& x);
|
| 1834 |
iterator insert(const_iterator position, size_type n, const T& x);
|
| 1835 |
template <class InputIterator>
|
| 1836 |
+
iterator insert(const_iterator position, InputIterator first, InputIterator last);
|
|
|
|
| 1837 |
iterator insert(const_iterator position, initializer_list<T> il);
|
| 1838 |
iterator erase(const_iterator position);
|
| 1839 |
iterator erase(const_iterator first, const_iterator last);
|
| 1840 |
+
void swap(vector&)
|
| 1841 |
+
noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
|
| 1842 |
+
allocator_traits<Allocator>::is_always_equal::value);
|
| 1843 |
void clear() noexcept;
|
| 1844 |
};
|
| 1845 |
|
| 1846 |
+
template<class InputIterator,
|
| 1847 |
+
class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
|
| 1848 |
+
vector(InputIterator, InputIterator, Allocator = Allocator())
|
| 1849 |
+
-> vector<typename iterator_traits<InputIterator>::value_type, Allocator>;
|
| 1850 |
+
|
| 1851 |
template <class T, class Allocator>
|
| 1852 |
bool operator==(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 1853 |
template <class T, class Allocator>
|
| 1854 |
bool operator< (const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 1855 |
template <class T, class Allocator>
|
|
|
|
| 1859 |
template <class T, class Allocator>
|
| 1860 |
bool operator>=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 1861 |
template <class T, class Allocator>
|
| 1862 |
bool operator<=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 1863 |
|
| 1864 |
+
// [vector.special], specialized algorithms
|
| 1865 |
template <class T, class Allocator>
|
| 1866 |
+
void swap(vector<T, Allocator>& x, vector<T, Allocator>& y)
|
| 1867 |
+
noexcept(noexcept(x.swap(y)));
|
| 1868 |
}
|
| 1869 |
```
|
| 1870 |
|
| 1871 |
+
An incomplete type `T` may be used when instantiating `vector` if the
|
| 1872 |
+
allocator satisfies the allocator completeness requirements (
|
| 1873 |
+
[[allocator.requirements.completeness]]). `T` shall be complete before
|
| 1874 |
+
any member of the resulting specialization of `vector` is referenced.
|
| 1875 |
+
|
| 1876 |
#### `vector` constructors, copy, and assignment <a id="vector.cons">[[vector.cons]]</a>
|
| 1877 |
|
| 1878 |
``` cpp
|
| 1879 |
explicit vector(const Allocator&);
|
| 1880 |
```
|
|
|
|
| 1915 |
*Effects:* Constructs a `vector` equal to the range \[`first`, `last`),
|
| 1916 |
using the specified allocator.
|
| 1917 |
|
| 1918 |
*Complexity:* Makes only N calls to the copy constructor of `T` (where N
|
| 1919 |
is the distance between `first` and `last`) and no reallocations if
|
| 1920 |
+
iterators `first` and `last` are of forward, bidirectional, or random
|
| 1921 |
+
access categories. It makes order `N` calls to the copy constructor of
|
| 1922 |
+
`T` and order log N reallocations if they are just input iterators.
|
| 1923 |
|
| 1924 |
#### `vector` capacity <a id="vector.capacity">[[vector.capacity]]</a>
|
| 1925 |
|
| 1926 |
``` cpp
|
| 1927 |
size_type capacity() const noexcept;
|
|
|
|
| 1960 |
void shrink_to_fit();
|
| 1961 |
```
|
| 1962 |
|
| 1963 |
*Requires:* `T` shall be `MoveInsertable` into `*this`.
|
| 1964 |
|
| 1965 |
+
*Effects:* `shrink_to_fit` is a non-binding request to reduce
|
| 1966 |
+
`capacity()` to `size()`.
|
| 1967 |
+
|
| 1968 |
+
[*Note 1*: The request is non-binding to allow latitude for
|
| 1969 |
+
implementation-specific optimizations. — *end note*]
|
| 1970 |
+
|
| 1971 |
+
It does not increase `capacity()`, but may reduce `capacity()` by
|
| 1972 |
+
causing reallocation. If an exception is thrown other than by the move
|
| 1973 |
+
constructor of a non-`CopyInsertable` `T` there are no effects.
|
| 1974 |
+
|
| 1975 |
*Complexity:* Linear in the size of the sequence.
|
| 1976 |
|
| 1977 |
+
*Remarks:* Reallocation invalidates all the references, pointers, and
|
| 1978 |
+
iterators referring to the elements in the sequence as well as the
|
| 1979 |
+
past-the-end iterator. If no reallocation happens, they remain valid.
|
|
|
|
|
|
|
| 1980 |
|
| 1981 |
``` cpp
|
| 1982 |
+
void swap(vector& x)
|
| 1983 |
+
noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
|
| 1984 |
+
allocator_traits<Allocator>::is_always_equal::value);
|
| 1985 |
```
|
| 1986 |
|
| 1987 |
*Effects:* Exchanges the contents and `capacity()` of `*this` with that
|
| 1988 |
of `x`.
|
| 1989 |
|
|
|
|
| 1991 |
|
| 1992 |
``` cpp
|
| 1993 |
void resize(size_type sz);
|
| 1994 |
```
|
| 1995 |
|
| 1996 |
+
*Effects:* If `sz < size()`, erases the last `size() - sz` elements from
|
| 1997 |
+
the sequence. Otherwise, appends `sz - size()` default-inserted elements
|
| 1998 |
+
to the sequence.
|
| 1999 |
|
| 2000 |
*Requires:* `T` shall be `MoveInsertable` and `DefaultInsertable` into
|
| 2001 |
`*this`.
|
| 2002 |
|
| 2003 |
*Remarks:* If an exception is thrown other than by the move constructor
|
|
|
|
| 2005 |
|
| 2006 |
``` cpp
|
| 2007 |
void resize(size_type sz, const T& c);
|
| 2008 |
```
|
| 2009 |
|
| 2010 |
+
*Effects:* If `sz < size()`, erases the last `size() - sz` elements from
|
| 2011 |
+
the sequence. Otherwise, appends `sz - size()` copies of `c` to the
|
| 2012 |
+
sequence.
|
| 2013 |
|
| 2014 |
*Requires:* `T` shall be `CopyInsertable` into `*this`.
|
| 2015 |
|
| 2016 |
*Remarks:* If an exception is thrown there are no effects.
|
| 2017 |
|
|
|
|
| 2021 |
T* data() noexcept;
|
| 2022 |
const T* data() const noexcept;
|
| 2023 |
```
|
| 2024 |
|
| 2025 |
*Returns:* A pointer such that \[`data()`, `data() + size()`) is a valid
|
| 2026 |
+
range. For a non-empty vector, `data()` `==` `addressof(front())`.
|
| 2027 |
|
| 2028 |
*Complexity:* Constant time.
|
| 2029 |
|
| 2030 |
#### `vector` modifiers <a id="vector.modifiers">[[vector.modifiers]]</a>
|
| 2031 |
|
|
|
|
| 2035 |
iterator insert(const_iterator position, size_type n, const T& x);
|
| 2036 |
template <class InputIterator>
|
| 2037 |
iterator insert(const_iterator position, InputIterator first, InputIterator last);
|
| 2038 |
iterator insert(const_iterator position, initializer_list<T>);
|
| 2039 |
|
| 2040 |
+
template <class... Args> reference emplace_back(Args&&... args);
|
| 2041 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 2042 |
void push_back(const T& x);
|
| 2043 |
void push_back(T&& x);
|
| 2044 |
```
|
| 2045 |
|
| 2046 |
*Remarks:* Causes reallocation if the new size is greater than the old
|
| 2047 |
+
capacity. Reallocation invalidates all the references, pointers, and
|
| 2048 |
+
iterators referring to the elements in the sequence. If no reallocation
|
| 2049 |
+
happens, all the iterators and references before the insertion point
|
| 2050 |
+
remain valid. If an exception is thrown other than by the copy
|
| 2051 |
+
constructor, move constructor, assignment operator, or move assignment
|
| 2052 |
+
operator of `T` or by any `InputIterator` operation there are no
|
| 2053 |
+
effects. If an exception is thrown while inserting a single element at
|
| 2054 |
+
the end and `T` is `CopyInsertable` or
|
| 2055 |
+
`is_nothrow_move_constructible_v<T>` is `true`, there are no effects.
|
| 2056 |
+
Otherwise, if an exception is thrown by the move constructor of a
|
| 2057 |
+
non-`CopyInsertable` `T`, the effects are unspecified.
|
| 2058 |
|
| 2059 |
*Complexity:* The complexity is linear in the number of elements
|
| 2060 |
inserted plus the distance to the end of the vector.
|
| 2061 |
|
| 2062 |
``` cpp
|
| 2063 |
iterator erase(const_iterator position);
|
| 2064 |
iterator erase(const_iterator first, const_iterator last);
|
| 2065 |
+
void pop_back();
|
| 2066 |
```
|
| 2067 |
|
| 2068 |
*Effects:* Invalidates iterators and references at or after the point of
|
| 2069 |
the erase.
|
| 2070 |
|
| 2071 |
*Complexity:* The destructor of `T` is called the number of times equal
|
| 2072 |
+
to the number of the elements erased, but the assignment operator of `T`
|
| 2073 |
+
is called the number of times equal to the number of elements in the
|
| 2074 |
+
vector after the erased elements.
|
| 2075 |
|
| 2076 |
+
*Throws:* Nothing unless an exception is thrown by the assignment
|
| 2077 |
+
operator or move assignment operator of `T`.
|
|
|
|
| 2078 |
|
| 2079 |
#### `vector` specialized algorithms <a id="vector.special">[[vector.special]]</a>
|
| 2080 |
|
| 2081 |
``` cpp
|
| 2082 |
template <class T, class Allocator>
|
| 2083 |
+
void swap(vector<T, Allocator>& x, vector<T, Allocator>& y)
|
| 2084 |
+
noexcept(noexcept(x.swap(y)));
|
| 2085 |
```
|
| 2086 |
|
| 2087 |
+
*Effects:* As if by `x.swap(y)`.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2088 |
|
| 2089 |
### Class `vector<bool>` <a id="vector.bool">[[vector.bool]]</a>
|
| 2090 |
|
| 2091 |
To optimize space allocation, a specialization of vector for `bool`
|
| 2092 |
elements is provided:
|
| 2093 |
|
| 2094 |
``` cpp
|
| 2095 |
namespace std {
|
| 2096 |
+
template <class Allocator>
|
| 2097 |
+
class vector<bool, Allocator> {
|
| 2098 |
public:
|
| 2099 |
// types:
|
| 2100 |
+
using value_type = bool;
|
| 2101 |
+
using allocator_type = Allocator;
|
| 2102 |
+
using pointer = implementation-defined;
|
| 2103 |
+
using const_pointer = implementation-defined;
|
| 2104 |
+
using const_reference = bool;
|
| 2105 |
+
using size_type = implementation-defined; // see [container.requirements]
|
| 2106 |
+
using difference_type = implementation-defined; // see [container.requirements]
|
| 2107 |
+
using iterator = implementation-defined // type of vector<bool>::iterator; // see [container.requirements]
|
| 2108 |
+
using const_iterator = implementation-defined // type of vector<bool>::const_iterator; // see [container.requirements]
|
| 2109 |
+
using reverse_iterator = std::reverse_iterator<iterator>;
|
| 2110 |
+
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
| 2111 |
|
| 2112 |
// bit reference:
|
| 2113 |
class reference {
|
| 2114 |
friend class vector;
|
| 2115 |
reference() noexcept;
|
|
|
|
| 2159 |
const_iterator cend() const noexcept;
|
| 2160 |
const_reverse_iterator crbegin() const noexcept;
|
| 2161 |
const_reverse_iterator crend() const noexcept;
|
| 2162 |
|
| 2163 |
// capacity:
|
| 2164 |
+
bool empty() const noexcept;
|
| 2165 |
size_type size() const noexcept;
|
| 2166 |
size_type max_size() const noexcept;
|
| 2167 |
+
size_type capacity() const noexcept;
|
| 2168 |
void resize(size_type sz, bool c = false);
|
|
|
|
|
|
|
| 2169 |
void reserve(size_type n);
|
| 2170 |
void shrink_to_fit();
|
| 2171 |
|
| 2172 |
// element access:
|
| 2173 |
reference operator[](size_type n);
|
|
|
|
| 2178 |
const_reference front() const;
|
| 2179 |
reference back();
|
| 2180 |
const_reference back() const;
|
| 2181 |
|
| 2182 |
// modifiers:
|
| 2183 |
+
template <class... Args> reference emplace_back(Args&&... args);
|
| 2184 |
void push_back(const bool& x);
|
| 2185 |
void pop_back();
|
| 2186 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 2187 |
iterator insert(const_iterator position, const bool& x);
|
| 2188 |
iterator insert(const_iterator position, size_type n, const bool& x);
|
|
|
|
| 2202 |
```
|
| 2203 |
|
| 2204 |
Unless described below, all operations have the same requirements and
|
| 2205 |
semantics as the primary `vector` template, except that operations
|
| 2206 |
dealing with the `bool` value type map to bit values in the container
|
| 2207 |
+
storage and `allocator_traits::construct` (
|
| 2208 |
+
[[allocator.traits.members]]) is not used to construct these values.
|
| 2209 |
|
| 2210 |
There is no requirement that the data be stored as a contiguous
|
| 2211 |
allocation of `bool` values. A space-optimized representation of bits is
|
| 2212 |
recommended instead.
|
| 2213 |
|
| 2214 |
`reference`
|
| 2215 |
|
| 2216 |
is a class that simulates the behavior of references of a single bit in
|
| 2217 |
+
`vector<bool>`. The conversion function returns `true` when the bit is
|
| 2218 |
set, and `false` otherwise. The assignment operator sets the bit when
|
| 2219 |
the argument is (convertible to) `true` and clears it otherwise. `flip`
|
| 2220 |
reverses the state of the bit.
|
| 2221 |
|
| 2222 |
``` cpp
|
|
|
|
| 2227 |
|
| 2228 |
``` cpp
|
| 2229 |
static void swap(reference x, reference y) noexcept;
|
| 2230 |
```
|
| 2231 |
|
| 2232 |
+
*Effects:* Exchanges the contents of `x` and `y` as if by:
|
| 2233 |
|
| 2234 |
``` cpp
|
| 2235 |
bool b = x;
|
| 2236 |
x = y;
|
| 2237 |
y = b;
|
|
|
|
| 2239 |
|
| 2240 |
``` cpp
|
| 2241 |
template <class Allocator> struct hash<vector<bool, Allocator>>;
|
| 2242 |
```
|
| 2243 |
|
| 2244 |
+
The specialization is enabled ([[unord.hash]]).
|
|
|
|
| 2245 |
|