tmp/tmp5lwfn90h/{from.md → to.md}
RENAMED
|
@@ -1,27 +1,20 @@
|
|
| 1 |
### Sequence containers <a id="sequence.reqmts">[[sequence.reqmts]]</a>
|
| 2 |
|
| 3 |
A sequence container organizes a finite set of objects, all of the same
|
| 4 |
-
type, into a strictly linear arrangement. The library provides
|
| 5 |
-
basic kinds of sequence containers: `vector`,
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
easy to construct abstract data types, such as `stack`s, `queue`s,
|
| 10 |
`flat_map`s, `flat_multimap`s, `flat_set`s, or `flat_multiset`s, out of
|
| 11 |
the basic sequence container kinds (or out of other program-defined
|
| 12 |
sequence containers).
|
| 13 |
|
| 14 |
-
[*Note 1*: The sequence containers offer the programmer different
|
| 15 |
-
complexity trade-offs. `vector` is appropriate in most circumstances.
|
| 16 |
-
`array` has a fixed size known during translation. `list` or
|
| 17 |
-
`forward_list` support frequent insertions and deletions from the middle
|
| 18 |
-
of the sequence. `deque` supports efficient insertions and deletions
|
| 19 |
-
taking place at the beginning or at the end of the sequence. When
|
| 20 |
-
choosing a container, remember `vector` is best; leave a comment to
|
| 21 |
-
explain if you choose from the rest! — *end note*]
|
| 22 |
-
|
| 23 |
In this subclause,
|
| 24 |
|
| 25 |
- `X` denotes a sequence container class,
|
| 26 |
- `a` denotes a value of type `X` containing elements of type `T`,
|
| 27 |
- `u` denotes the name of a variable being declared,
|
|
@@ -29,18 +22,18 @@ In this subclause,
|
|
| 29 |
`X::allocator_type` is valid and denotes a type [[temp.deduct]] and
|
| 30 |
`allocator<T>` if it doesn’t,
|
| 31 |
- `i` and `j` denote iterators that meet the *Cpp17InputIterator*
|
| 32 |
requirements and refer to elements implicitly convertible to
|
| 33 |
`value_type`,
|
| 34 |
-
-
|
| 35 |
- `rg` denotes a value of a type `R` that models
|
| 36 |
`container-compatible-range<T>`,
|
| 37 |
- `il` designates an object of type `initializer_list<value_type>`,
|
| 38 |
- `n` denotes a value of type `X::size_type`,
|
| 39 |
- `p` denotes a valid constant iterator to `a`,
|
| 40 |
- `q` denotes a valid dereferenceable constant iterator to `a`,
|
| 41 |
-
-
|
| 42 |
- `t` denotes an lvalue or a const rvalue of `X::value_type`, and
|
| 43 |
- `rv` denotes a non-const rvalue of `X::value_type`.
|
| 44 |
- `Args` denotes a template parameter pack;
|
| 45 |
- `args` denotes a function parameter pack with the pattern `Args&&`.
|
| 46 |
|
|
@@ -67,27 +60,34 @@ X u(i, j);
|
|
| 67 |
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `X` from `*i`.
|
| 68 |
For `vector`, if the iterator does not meet the *Cpp17ForwardIterator*
|
| 69 |
requirements [[forward.iterators]], `T` is also *Cpp17MoveInsertable*
|
| 70 |
into `X`.
|
| 71 |
|
| 72 |
-
*Effects:* Constructs a sequence container equal to the range
|
| 73 |
-
Each iterator in the range \[`i`, `j`) is dereferenced exactly
|
|
|
|
| 74 |
|
| 75 |
*Ensures:* `distance(u.begin(), u.end()) == distance(i, j)` is `true`.
|
| 76 |
|
| 77 |
``` cpp
|
| 78 |
X(from_range, rg)
|
| 79 |
```
|
| 80 |
|
| 81 |
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `X` from
|
| 82 |
-
`*ranges::begin(rg)`. For `vector`, if `R` models
|
| 83 |
-
`ranges::
|
| 84 |
-
|
|
|
|
| 85 |
|
| 86 |
*Effects:* Constructs a sequence container equal to the range `rg`. Each
|
| 87 |
iterator in the range `rg` is dereferenced exactly once.
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
*Ensures:* `distance(begin(), end()) == ranges::distance(rg)` is `true`.
|
| 90 |
|
| 91 |
``` cpp
|
| 92 |
X(il)
|
| 93 |
```
|
|
@@ -113,30 +113,29 @@ a.emplace(p, args)
|
|
| 113 |
```
|
| 114 |
|
| 115 |
*Result:* `iterator`.
|
| 116 |
|
| 117 |
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `X` from
|
| 118 |
-
`args`. For `vector` and `deque`, `T` is also
|
| 119 |
-
`X` and *Cpp17MoveAssignable*.
|
| 120 |
|
| 121 |
*Effects:* Inserts an object of type `T` constructed with
|
| 122 |
`std::forward<Args>(args)...` before `p`.
|
| 123 |
|
| 124 |
[*Note 1*: `args` can directly or indirectly refer to a value in
|
| 125 |
`a`. — *end note*]
|
| 126 |
|
| 127 |
-
*Returns:* An iterator that points to the new element
|
| 128 |
-
`args` into `a`.
|
| 129 |
|
| 130 |
``` cpp
|
| 131 |
a.insert(p, t)
|
| 132 |
```
|
| 133 |
|
| 134 |
*Result:* `iterator`.
|
| 135 |
|
| 136 |
-
*Preconditions:* `T` is *Cpp17CopyInsertable* into `X`. For `vector`
|
| 137 |
-
`deque`, `T` is also *Cpp17CopyAssignable*.
|
| 138 |
|
| 139 |
*Effects:* Inserts a copy of `t` before `p`.
|
| 140 |
|
| 141 |
*Returns:* An iterator that points to the copy of `t` inserted into `a`.
|
| 142 |
|
|
@@ -144,12 +143,12 @@ a.insert(p, t)
|
|
| 144 |
a.insert(p, rv)
|
| 145 |
```
|
| 146 |
|
| 147 |
*Result:* `iterator`.
|
| 148 |
|
| 149 |
-
*Preconditions:* `T` is *Cpp17MoveInsertable* into `X`. For `vector`
|
| 150 |
-
`deque`, `T` is also *Cpp17MoveAssignable*.
|
| 151 |
|
| 152 |
*Effects:* Inserts a copy of `rv` before `p`.
|
| 153 |
|
| 154 |
*Returns:* An iterator that points to the copy of `rv` inserted into
|
| 155 |
`a`.
|
|
@@ -173,16 +172,17 @@ a.insert(p, i, j)
|
|
| 173 |
```
|
| 174 |
|
| 175 |
*Result:* `iterator`.
|
| 176 |
|
| 177 |
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `X` from `*i`.
|
| 178 |
-
For `vector` and `deque`, `T` is also
|
| 179 |
-
and `T` meets the
|
|
|
|
| 180 |
*Cpp17Swappable*[[swappable.requirements]] requirements. Neither `i` nor
|
| 181 |
`j` are iterators into `a`.
|
| 182 |
|
| 183 |
-
*Effects:* Inserts copies of elements in
|
| 184 |
iterator in the range \[`i`, `j`) shall be dereferenced exactly once.
|
| 185 |
|
| 186 |
*Returns:* An iterator that points to the copy of the first element
|
| 187 |
inserted into `a`, or `p` if `i == j`.
|
| 188 |
|
|
@@ -191,12 +191,12 @@ a.insert_range(p, rg)
|
|
| 191 |
```
|
| 192 |
|
| 193 |
*Result:* `iterator`.
|
| 194 |
|
| 195 |
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `X` from
|
| 196 |
-
`*ranges::begin(rg)`. For `vector` and `deque`, `T`
|
| 197 |
-
*Cpp17MoveInsertable* into `X`, and `T` meets the
|
| 198 |
*Cpp17MoveConstructible*, *Cpp17MoveAssignable*, and
|
| 199 |
*Cpp17Swappable*[[swappable.requirements]] requirements. `rg` and `a` do
|
| 200 |
not overlap.
|
| 201 |
|
| 202 |
*Effects:* Inserts copies of elements in `rg` before `p`. Each iterator
|
|
@@ -215,11 +215,12 @@ a.insert(p, il)
|
|
| 215 |
a.erase(q)
|
| 216 |
```
|
| 217 |
|
| 218 |
*Result:* `iterator`.
|
| 219 |
|
| 220 |
-
*Preconditions:* For `vector` and `deque`, `T` is
|
|
|
|
| 221 |
|
| 222 |
*Effects:* Erases the element pointed to by `q`.
|
| 223 |
|
| 224 |
*Returns:* An iterator that points to the element immediately following
|
| 225 |
`q` prior to the element being erased. If no such element exists,
|
|
@@ -229,13 +230,14 @@ a.erase(q)
|
|
| 229 |
a.erase(q1, q2)
|
| 230 |
```
|
| 231 |
|
| 232 |
*Result:* `iterator`.
|
| 233 |
|
| 234 |
-
*Preconditions:* For `vector` and `deque`, `T` is
|
|
|
|
| 235 |
|
| 236 |
-
*Effects:* Erases the elements in the range
|
| 237 |
|
| 238 |
*Returns:* An iterator that points to the element pointed to by `q2`
|
| 239 |
prior to any elements being erased. If no such element exists, `a.end()`
|
| 240 |
is returned.
|
| 241 |
|
|
@@ -263,14 +265,15 @@ a.assign(i, j)
|
|
| 263 |
and assignable from `*i`. For `vector`, if the iterator does not meet
|
| 264 |
the forward iterator requirements [[forward.iterators]], `T` is also
|
| 265 |
*Cpp17MoveInsertable* into `X`. Neither `i` nor `j` are iterators into
|
| 266 |
`a`.
|
| 267 |
|
| 268 |
-
*Effects:* Replaces elements in `a` with a copy of
|
| 269 |
-
all references, pointers and iterators referring to the
|
| 270 |
-
For `vector` and `deque`, also invalidates the
|
| 271 |
-
Each iterator in the range \[`i`, `j`) is
|
|
|
|
| 272 |
|
| 273 |
``` cpp
|
| 274 |
a.assign_range(rg)
|
| 275 |
```
|
| 276 |
|
|
@@ -278,20 +281,26 @@ a.assign_range(rg)
|
|
| 278 |
|
| 279 |
*Mandates:* `assignable_from<T&, ranges::range_reference_t<R>>` is
|
| 280 |
modeled.
|
| 281 |
|
| 282 |
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `X` from
|
| 283 |
-
`*ranges::begin(rg)`. For `vector`, if `R` models
|
| 284 |
-
`ranges::
|
| 285 |
-
|
|
|
|
| 286 |
|
| 287 |
*Effects:* Replaces elements in `a` with a copy of each element in `rg`.
|
| 288 |
Invalidates all references, pointers, and iterators referring to the
|
| 289 |
elements of `a`. For `vector` and `deque`, also invalidates the
|
| 290 |
past-the-end iterator. Each iterator in the range `rg` is dereferenced
|
| 291 |
exactly once.
|
| 292 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
``` cpp
|
| 294 |
a.assign(il)
|
| 295 |
```
|
| 296 |
|
| 297 |
*Effects:* Equivalent to `a.assign(il.begin(), il.end())`.
|
|
@@ -353,31 +362,35 @@ containers but not others. Operations other than `prepend_range` and
|
|
| 353 |
a.front()
|
| 354 |
```
|
| 355 |
|
| 356 |
*Result:* `reference; const_reference` for constant `a`.
|
| 357 |
|
|
|
|
|
|
|
| 358 |
*Returns:* `*a.begin()`
|
| 359 |
|
| 360 |
*Remarks:* Required for `basic_string`, `array`, `deque`,
|
| 361 |
-
`forward_list`, `list`, and `vector`.
|
| 362 |
|
| 363 |
``` cpp
|
| 364 |
a.back()
|
| 365 |
```
|
| 366 |
|
| 367 |
*Result:* `reference; const_reference` for constant `a`.
|
| 368 |
|
|
|
|
|
|
|
| 369 |
*Effects:* Equivalent to:
|
| 370 |
|
| 371 |
``` cpp
|
| 372 |
auto tmp = a.end();
|
| 373 |
--tmp;
|
| 374 |
return *tmp;
|
| 375 |
```
|
| 376 |
|
| 377 |
-
*Remarks:* Required for `basic_string`, `array`, `deque`,
|
| 378 |
-
`vector`.
|
| 379 |
|
| 380 |
``` cpp
|
| 381 |
a.emplace_front(args)
|
| 382 |
```
|
| 383 |
|
|
@@ -405,11 +418,11 @@ a.emplace_back(args)
|
|
| 405 |
*Effects:* Appends an object of type `T` constructed with
|
| 406 |
`std::forward<Args>(args)...`.
|
| 407 |
|
| 408 |
*Returns:* `a.back()`.
|
| 409 |
|
| 410 |
-
*Remarks:* Required for `deque`, `list`, and `vector`.
|
| 411 |
|
| 412 |
``` cpp
|
| 413 |
a.push_front(t)
|
| 414 |
```
|
| 415 |
|
|
@@ -461,11 +474,12 @@ a.push_back(t)
|
|
| 461 |
|
| 462 |
*Preconditions:* `T` is *Cpp17CopyInsertable* into `X`.
|
| 463 |
|
| 464 |
*Effects:* Appends a copy of `t`.
|
| 465 |
|
| 466 |
-
*Remarks:* Required for `basic_string`, `deque`, `
|
|
|
|
| 467 |
|
| 468 |
``` cpp
|
| 469 |
a.push_back(rv)
|
| 470 |
```
|
| 471 |
|
|
@@ -473,11 +487,12 @@ a.push_back(rv)
|
|
| 473 |
|
| 474 |
*Preconditions:* `T` is *Cpp17MoveInsertable* into `X`.
|
| 475 |
|
| 476 |
*Effects:* Appends a copy of `rv`.
|
| 477 |
|
| 478 |
-
*Remarks:* Required for `basic_string`, `deque`, `
|
|
|
|
| 479 |
|
| 480 |
``` cpp
|
| 481 |
a.append_range(rg)
|
| 482 |
```
|
| 483 |
|
|
@@ -488,19 +503,19 @@ a.append_range(rg)
|
|
| 488 |
into `X`.
|
| 489 |
|
| 490 |
*Effects:* Inserts copies of elements in `rg` before `end()`. Each
|
| 491 |
iterator in the range `rg` is dereferenced exactly once.
|
| 492 |
|
| 493 |
-
*Remarks:* Required for `deque`, `list`, and `vector`.
|
| 494 |
|
| 495 |
``` cpp
|
| 496 |
a.pop_front()
|
| 497 |
```
|
| 498 |
|
| 499 |
*Result:* `void`
|
| 500 |
|
| 501 |
-
|
| 502 |
|
| 503 |
*Effects:* Destroys the first element.
|
| 504 |
|
| 505 |
*Remarks:* Required for `deque`, `forward_list`, and `list`.
|
| 506 |
|
|
@@ -508,33 +523,38 @@ a.pop_front()
|
|
| 508 |
a.pop_back()
|
| 509 |
```
|
| 510 |
|
| 511 |
*Result:* `void`
|
| 512 |
|
| 513 |
-
|
| 514 |
|
| 515 |
*Effects:* Destroys the last element.
|
| 516 |
|
| 517 |
-
*Remarks:* Required for `basic_string`, `deque`, `
|
|
|
|
| 518 |
|
| 519 |
``` cpp
|
| 520 |
a[n]
|
| 521 |
```
|
| 522 |
|
| 523 |
-
*Result:* `reference; const_reference` for constant `a`
|
| 524 |
|
| 525 |
-
|
| 526 |
|
| 527 |
-
*
|
|
|
|
|
|
|
|
|
|
| 528 |
|
| 529 |
``` cpp
|
| 530 |
a.at(n)
|
| 531 |
```
|
| 532 |
|
| 533 |
-
*Result:* `reference; const_reference` for constant `a`
|
| 534 |
|
| 535 |
*Returns:* `*(a.begin() + n)`
|
| 536 |
|
| 537 |
*Throws:* `out_of_range` if `n >= a.size()`.
|
| 538 |
|
| 539 |
-
*Remarks:* Required for `basic_string`, `array`, `deque`,
|
|
|
|
| 540 |
|
|
|
|
| 1 |
### Sequence containers <a id="sequence.reqmts">[[sequence.reqmts]]</a>
|
| 2 |
|
| 3 |
A sequence container organizes a finite set of objects, all of the same
|
| 4 |
+
type, into a strictly linear arrangement. The library provides the
|
| 5 |
+
following basic kinds of sequence containers: `vector`,
|
| 6 |
+
`inplace_vector`, `forward_list`, `list`, and `deque`. In addition,
|
| 7 |
+
`array` and `hive` are provided as sequence containers which provide
|
| 8 |
+
limited sequence operations, in `array`’s case because it has a fixed
|
| 9 |
+
number of elements, and in `hive`’s case because insertion order is
|
| 10 |
+
unspecified. The library also provides container adaptors that make it
|
| 11 |
easy to construct abstract data types, such as `stack`s, `queue`s,
|
| 12 |
`flat_map`s, `flat_multimap`s, `flat_set`s, or `flat_multiset`s, out of
|
| 13 |
the basic sequence container kinds (or out of other program-defined
|
| 14 |
sequence containers).
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
In this subclause,
|
| 17 |
|
| 18 |
- `X` denotes a sequence container class,
|
| 19 |
- `a` denotes a value of type `X` containing elements of type `T`,
|
| 20 |
- `u` denotes the name of a variable being declared,
|
|
|
|
| 22 |
`X::allocator_type` is valid and denotes a type [[temp.deduct]] and
|
| 23 |
`allocator<T>` if it doesn’t,
|
| 24 |
- `i` and `j` denote iterators that meet the *Cpp17InputIterator*
|
| 25 |
requirements and refer to elements implicitly convertible to
|
| 26 |
`value_type`,
|
| 27 |
+
- \[`i`, `j`) denotes a valid range,
|
| 28 |
- `rg` denotes a value of a type `R` that models
|
| 29 |
`container-compatible-range<T>`,
|
| 30 |
- `il` designates an object of type `initializer_list<value_type>`,
|
| 31 |
- `n` denotes a value of type `X::size_type`,
|
| 32 |
- `p` denotes a valid constant iterator to `a`,
|
| 33 |
- `q` denotes a valid dereferenceable constant iterator to `a`,
|
| 34 |
+
- \[`q1`, `q2`) denotes a valid range of constant iterators in `a`,
|
| 35 |
- `t` denotes an lvalue or a const rvalue of `X::value_type`, and
|
| 36 |
- `rv` denotes a non-const rvalue of `X::value_type`.
|
| 37 |
- `Args` denotes a template parameter pack;
|
| 38 |
- `args` denotes a function parameter pack with the pattern `Args&&`.
|
| 39 |
|
|
|
|
| 60 |
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `X` from `*i`.
|
| 61 |
For `vector`, if the iterator does not meet the *Cpp17ForwardIterator*
|
| 62 |
requirements [[forward.iterators]], `T` is also *Cpp17MoveInsertable*
|
| 63 |
into `X`.
|
| 64 |
|
| 65 |
+
*Effects:* Constructs a sequence container equal to the range \[`i`,
|
| 66 |
+
`j`). Each iterator in the range \[`i`, `j`) is dereferenced exactly
|
| 67 |
+
once.
|
| 68 |
|
| 69 |
*Ensures:* `distance(u.begin(), u.end()) == distance(i, j)` is `true`.
|
| 70 |
|
| 71 |
``` cpp
|
| 72 |
X(from_range, rg)
|
| 73 |
```
|
| 74 |
|
| 75 |
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `X` from
|
| 76 |
+
`*ranges::begin(rg)`. For `vector`, if `R` models
|
| 77 |
+
`ranges::approximately_sized_range` but not `ranges::sized_range` or
|
| 78 |
+
models `ranges::input_range` but not `ranges::forward_range`, `T` is
|
| 79 |
+
also *Cpp17MoveInsertable* into `X`.
|
| 80 |
|
| 81 |
*Effects:* Constructs a sequence container equal to the range `rg`. Each
|
| 82 |
iterator in the range `rg` is dereferenced exactly once.
|
| 83 |
|
| 84 |
+
*Recommended practice:* If `R` models
|
| 85 |
+
`ranges::approximately_sized_range` and
|
| 86 |
+
`ranges::distance(rg) <= ranges::reserve_hint(rg)` is `true`, an
|
| 87 |
+
implementation should not perform more than a single reallocation.
|
| 88 |
+
|
| 89 |
*Ensures:* `distance(begin(), end()) == ranges::distance(rg)` is `true`.
|
| 90 |
|
| 91 |
``` cpp
|
| 92 |
X(il)
|
| 93 |
```
|
|
|
|
| 113 |
```
|
| 114 |
|
| 115 |
*Result:* `iterator`.
|
| 116 |
|
| 117 |
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `X` from
|
| 118 |
+
`args`. For `vector`, `inplace_vector`, and `deque`, `T` is also
|
| 119 |
+
*Cpp17MoveInsertable* into `X` and *Cpp17MoveAssignable*.
|
| 120 |
|
| 121 |
*Effects:* Inserts an object of type `T` constructed with
|
| 122 |
`std::forward<Args>(args)...` before `p`.
|
| 123 |
|
| 124 |
[*Note 1*: `args` can directly or indirectly refer to a value in
|
| 125 |
`a`. — *end note*]
|
| 126 |
|
| 127 |
+
*Returns:* An iterator that points to the new element.
|
|
|
|
| 128 |
|
| 129 |
``` cpp
|
| 130 |
a.insert(p, t)
|
| 131 |
```
|
| 132 |
|
| 133 |
*Result:* `iterator`.
|
| 134 |
|
| 135 |
+
*Preconditions:* `T` is *Cpp17CopyInsertable* into `X`. For `vector`,
|
| 136 |
+
`inplace_vector`, and `deque`, `T` is also *Cpp17CopyAssignable*.
|
| 137 |
|
| 138 |
*Effects:* Inserts a copy of `t` before `p`.
|
| 139 |
|
| 140 |
*Returns:* An iterator that points to the copy of `t` inserted into `a`.
|
| 141 |
|
|
|
|
| 143 |
a.insert(p, rv)
|
| 144 |
```
|
| 145 |
|
| 146 |
*Result:* `iterator`.
|
| 147 |
|
| 148 |
+
*Preconditions:* `T` is *Cpp17MoveInsertable* into `X`. For `vector`,
|
| 149 |
+
`inplace_vector`, and `deque`, `T` is also *Cpp17MoveAssignable*.
|
| 150 |
|
| 151 |
*Effects:* Inserts a copy of `rv` before `p`.
|
| 152 |
|
| 153 |
*Returns:* An iterator that points to the copy of `rv` inserted into
|
| 154 |
`a`.
|
|
|
|
| 172 |
```
|
| 173 |
|
| 174 |
*Result:* `iterator`.
|
| 175 |
|
| 176 |
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `X` from `*i`.
|
| 177 |
+
For `vector`, `inplace_vector`, and `deque`, `T` is also
|
| 178 |
+
*Cpp17MoveInsertable* into `X`, and `T` meets the
|
| 179 |
+
*Cpp17MoveConstructible*, *Cpp17MoveAssignable*, and
|
| 180 |
*Cpp17Swappable*[[swappable.requirements]] requirements. Neither `i` nor
|
| 181 |
`j` are iterators into `a`.
|
| 182 |
|
| 183 |
+
*Effects:* Inserts copies of elements in \[`i`, `j`) before `p`. Each
|
| 184 |
iterator in the range \[`i`, `j`) shall be dereferenced exactly once.
|
| 185 |
|
| 186 |
*Returns:* An iterator that points to the copy of the first element
|
| 187 |
inserted into `a`, or `p` if `i == j`.
|
| 188 |
|
|
|
|
| 191 |
```
|
| 192 |
|
| 193 |
*Result:* `iterator`.
|
| 194 |
|
| 195 |
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `X` from
|
| 196 |
+
`*ranges::begin(rg)`. For `vector`, `inplace_vector`, and `deque`, `T`
|
| 197 |
+
is also *Cpp17MoveInsertable* into `X`, and `T` meets the
|
| 198 |
*Cpp17MoveConstructible*, *Cpp17MoveAssignable*, and
|
| 199 |
*Cpp17Swappable*[[swappable.requirements]] requirements. `rg` and `a` do
|
| 200 |
not overlap.
|
| 201 |
|
| 202 |
*Effects:* Inserts copies of elements in `rg` before `p`. Each iterator
|
|
|
|
| 215 |
a.erase(q)
|
| 216 |
```
|
| 217 |
|
| 218 |
*Result:* `iterator`.
|
| 219 |
|
| 220 |
+
*Preconditions:* For `vector`, `inplace_vector`, and `deque`, `T` is
|
| 221 |
+
*Cpp17MoveAssignable*.
|
| 222 |
|
| 223 |
*Effects:* Erases the element pointed to by `q`.
|
| 224 |
|
| 225 |
*Returns:* An iterator that points to the element immediately following
|
| 226 |
`q` prior to the element being erased. If no such element exists,
|
|
|
|
| 230 |
a.erase(q1, q2)
|
| 231 |
```
|
| 232 |
|
| 233 |
*Result:* `iterator`.
|
| 234 |
|
| 235 |
+
*Preconditions:* For `vector`, `inplace_vector`, and `deque`, `T` is
|
| 236 |
+
*Cpp17MoveAssignable*.
|
| 237 |
|
| 238 |
+
*Effects:* Erases the elements in the range \[`q1`, `q2`).
|
| 239 |
|
| 240 |
*Returns:* An iterator that points to the element pointed to by `q2`
|
| 241 |
prior to any elements being erased. If no such element exists, `a.end()`
|
| 242 |
is returned.
|
| 243 |
|
|
|
|
| 265 |
and assignable from `*i`. For `vector`, if the iterator does not meet
|
| 266 |
the forward iterator requirements [[forward.iterators]], `T` is also
|
| 267 |
*Cpp17MoveInsertable* into `X`. Neither `i` nor `j` are iterators into
|
| 268 |
`a`.
|
| 269 |
|
| 270 |
+
*Effects:* Replaces elements in `a` with a copy of \[`i`, `j`).
|
| 271 |
+
Invalidates all references, pointers and iterators referring to the
|
| 272 |
+
elements of `a`. For `vector` and `deque`, also invalidates the
|
| 273 |
+
past-the-end iterator. Each iterator in the range \[`i`, `j`) is
|
| 274 |
+
dereferenced exactly once.
|
| 275 |
|
| 276 |
``` cpp
|
| 277 |
a.assign_range(rg)
|
| 278 |
```
|
| 279 |
|
|
|
|
| 281 |
|
| 282 |
*Mandates:* `assignable_from<T&, ranges::range_reference_t<R>>` is
|
| 283 |
modeled.
|
| 284 |
|
| 285 |
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `X` from
|
| 286 |
+
`*ranges::begin(rg)`. For `vector`, if `R` models
|
| 287 |
+
`ranges::approximately_sized_range` but not `ranges::sized_range` or
|
| 288 |
+
models `ranges::input_range` but not `ranges::forward_range`, `T` is
|
| 289 |
+
also *Cpp17MoveInsertable* into `X`. `rg` and `a` do not overlap.
|
| 290 |
|
| 291 |
*Effects:* Replaces elements in `a` with a copy of each element in `rg`.
|
| 292 |
Invalidates all references, pointers, and iterators referring to the
|
| 293 |
elements of `a`. For `vector` and `deque`, also invalidates the
|
| 294 |
past-the-end iterator. Each iterator in the range `rg` is dereferenced
|
| 295 |
exactly once.
|
| 296 |
|
| 297 |
+
*Recommended practice:* If `R` models
|
| 298 |
+
`ranges::approximately_sized_range` and
|
| 299 |
+
`ranges::distance(rg) <= ranges::reserve_hint(rg)` is `true`, an
|
| 300 |
+
implementation should not perform any reallocation.
|
| 301 |
+
|
| 302 |
``` cpp
|
| 303 |
a.assign(il)
|
| 304 |
```
|
| 305 |
|
| 306 |
*Effects:* Equivalent to `a.assign(il.begin(), il.end())`.
|
|
|
|
| 362 |
a.front()
|
| 363 |
```
|
| 364 |
|
| 365 |
*Result:* `reference; const_reference` for constant `a`.
|
| 366 |
|
| 367 |
+
`a.empty()` is `false`.
|
| 368 |
+
|
| 369 |
*Returns:* `*a.begin()`
|
| 370 |
|
| 371 |
*Remarks:* Required for `basic_string`, `array`, `deque`,
|
| 372 |
+
`forward_list`, `inplace_vector`, `list`, and `vector`.
|
| 373 |
|
| 374 |
``` cpp
|
| 375 |
a.back()
|
| 376 |
```
|
| 377 |
|
| 378 |
*Result:* `reference; const_reference` for constant `a`.
|
| 379 |
|
| 380 |
+
`a.empty()` is `false`.
|
| 381 |
+
|
| 382 |
*Effects:* Equivalent to:
|
| 383 |
|
| 384 |
``` cpp
|
| 385 |
auto tmp = a.end();
|
| 386 |
--tmp;
|
| 387 |
return *tmp;
|
| 388 |
```
|
| 389 |
|
| 390 |
+
*Remarks:* Required for `basic_string`, `array`, `deque`,
|
| 391 |
+
`inplace_vector`, `list`, and `vector`.
|
| 392 |
|
| 393 |
``` cpp
|
| 394 |
a.emplace_front(args)
|
| 395 |
```
|
| 396 |
|
|
|
|
| 418 |
*Effects:* Appends an object of type `T` constructed with
|
| 419 |
`std::forward<Args>(args)...`.
|
| 420 |
|
| 421 |
*Returns:* `a.back()`.
|
| 422 |
|
| 423 |
+
*Remarks:* Required for `deque`, `inplace_vector`, `list`, and `vector`.
|
| 424 |
|
| 425 |
``` cpp
|
| 426 |
a.push_front(t)
|
| 427 |
```
|
| 428 |
|
|
|
|
| 474 |
|
| 475 |
*Preconditions:* `T` is *Cpp17CopyInsertable* into `X`.
|
| 476 |
|
| 477 |
*Effects:* Appends a copy of `t`.
|
| 478 |
|
| 479 |
+
*Remarks:* Required for `basic_string`, `deque`, `inplace_vector`,
|
| 480 |
+
`list`, and `vector`.
|
| 481 |
|
| 482 |
``` cpp
|
| 483 |
a.push_back(rv)
|
| 484 |
```
|
| 485 |
|
|
|
|
| 487 |
|
| 488 |
*Preconditions:* `T` is *Cpp17MoveInsertable* into `X`.
|
| 489 |
|
| 490 |
*Effects:* Appends a copy of `rv`.
|
| 491 |
|
| 492 |
+
*Remarks:* Required for `basic_string`, `deque`, `inplace_vector`,
|
| 493 |
+
`list`, and `vector`.
|
| 494 |
|
| 495 |
``` cpp
|
| 496 |
a.append_range(rg)
|
| 497 |
```
|
| 498 |
|
|
|
|
| 503 |
into `X`.
|
| 504 |
|
| 505 |
*Effects:* Inserts copies of elements in `rg` before `end()`. Each
|
| 506 |
iterator in the range `rg` is dereferenced exactly once.
|
| 507 |
|
| 508 |
+
*Remarks:* Required for `deque`, `inplace_vector`, `list`, and `vector`.
|
| 509 |
|
| 510 |
``` cpp
|
| 511 |
a.pop_front()
|
| 512 |
```
|
| 513 |
|
| 514 |
*Result:* `void`
|
| 515 |
|
| 516 |
+
`a.empty()` is `false`.
|
| 517 |
|
| 518 |
*Effects:* Destroys the first element.
|
| 519 |
|
| 520 |
*Remarks:* Required for `deque`, `forward_list`, and `list`.
|
| 521 |
|
|
|
|
| 523 |
a.pop_back()
|
| 524 |
```
|
| 525 |
|
| 526 |
*Result:* `void`
|
| 527 |
|
| 528 |
+
`a.empty()` is `false`.
|
| 529 |
|
| 530 |
*Effects:* Destroys the last element.
|
| 531 |
|
| 532 |
+
*Remarks:* Required for `basic_string`, `deque`, `inplace_vector`,
|
| 533 |
+
`list`, and `vector`.
|
| 534 |
|
| 535 |
``` cpp
|
| 536 |
a[n]
|
| 537 |
```
|
| 538 |
|
| 539 |
+
*Result:* `reference; const_reference` for constant `a`.
|
| 540 |
|
| 541 |
+
`n < a.size()` is `true`.
|
| 542 |
|
| 543 |
+
*Effects:* Equivalent to: `return *(a.begin() + n);`
|
| 544 |
+
|
| 545 |
+
*Remarks:* Required for `basic_string`, `array`, `deque`,
|
| 546 |
+
`inplace_vector`, and `vector`.
|
| 547 |
|
| 548 |
``` cpp
|
| 549 |
a.at(n)
|
| 550 |
```
|
| 551 |
|
| 552 |
+
*Result:* `reference; const_reference` for constant `a`.
|
| 553 |
|
| 554 |
*Returns:* `*(a.begin() + n)`
|
| 555 |
|
| 556 |
*Throws:* `out_of_range` if `n >= a.size()`.
|
| 557 |
|
| 558 |
+
*Remarks:* Required for `basic_string`, `array`, `deque`,
|
| 559 |
+
`inplace_vector`, and `vector`.
|
| 560 |
|