- tmp/tmp3ehaz_90/{from.md → to.md} +95 -100
tmp/tmp3ehaz_90/{from.md → to.md}
RENAMED
|
@@ -1,33 +1,31 @@
|
|
| 1 |
### Class template `list` <a id="list">[[list]]</a>
|
| 2 |
|
| 3 |
-
####
|
| 4 |
|
| 5 |
A `list` is a sequence container that supports bidirectional iterators
|
| 6 |
and allows constant time insert and erase operations anywhere within the
|
| 7 |
-
sequence, with storage management handled automatically. Unlike
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
access anyway.
|
| 11 |
|
| 12 |
-
A `list`
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
one of these tables or for operations where there is additional semantic
|
| 21 |
information.
|
| 22 |
|
| 23 |
``` cpp
|
| 24 |
namespace std {
|
| 25 |
template<class T, class Allocator = allocator<T>>
|
| 26 |
class list {
|
| 27 |
public:
|
| 28 |
-
// types
|
| 29 |
using value_type = T;
|
| 30 |
using allocator_type = Allocator;
|
| 31 |
using pointer = typename allocator_traits<Allocator>::pointer;
|
| 32 |
using const_pointer = typename allocator_traits<Allocator>::const_pointer;
|
| 33 |
using reference = value_type&;
|
|
@@ -60,11 +58,11 @@ namespace std {
|
|
| 60 |
void assign(InputIterator first, InputIterator last);
|
| 61 |
void assign(size_type n, const T& t);
|
| 62 |
void assign(initializer_list<T>);
|
| 63 |
allocator_type get_allocator() const noexcept;
|
| 64 |
|
| 65 |
-
// iterators
|
| 66 |
iterator begin() noexcept;
|
| 67 |
const_iterator begin() const noexcept;
|
| 68 |
iterator end() noexcept;
|
| 69 |
const_iterator end() const noexcept;
|
| 70 |
reverse_iterator rbegin() noexcept;
|
|
@@ -76,17 +74,17 @@ namespace std {
|
|
| 76 |
const_iterator cend() const noexcept;
|
| 77 |
const_reverse_iterator crbegin() const noexcept;
|
| 78 |
const_reverse_iterator crend() const noexcept;
|
| 79 |
|
| 80 |
// [list.capacity], capacity
|
| 81 |
-
bool
|
| 82 |
size_type size() const noexcept;
|
| 83 |
size_type max_size() const noexcept;
|
| 84 |
void resize(size_type sz);
|
| 85 |
void resize(size_type sz, const T& c);
|
| 86 |
|
| 87 |
-
// element access
|
| 88 |
reference front();
|
| 89 |
const_reference front() const;
|
| 90 |
reference back();
|
| 91 |
const_reference back() const;
|
| 92 |
|
|
@@ -103,36 +101,32 @@ namespace std {
|
|
| 103 |
template<class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 104 |
iterator insert(const_iterator position, const T& x);
|
| 105 |
iterator insert(const_iterator position, T&& x);
|
| 106 |
iterator insert(const_iterator position, size_type n, const T& x);
|
| 107 |
template<class InputIterator>
|
| 108 |
-
iterator insert(const_iterator position, InputIterator first,
|
| 109 |
-
InputIterator last);
|
| 110 |
iterator insert(const_iterator position, initializer_list<T> il);
|
| 111 |
|
| 112 |
iterator erase(const_iterator position);
|
| 113 |
iterator erase(const_iterator position, const_iterator last);
|
| 114 |
-
void swap(list&)
|
| 115 |
-
noexcept(allocator_traits<Allocator>::is_always_equal::value);
|
| 116 |
void clear() noexcept;
|
| 117 |
|
| 118 |
// [list.ops], list operations
|
| 119 |
void splice(const_iterator position, list& x);
|
| 120 |
void splice(const_iterator position, list&& x);
|
| 121 |
void splice(const_iterator position, list& x, const_iterator i);
|
| 122 |
void splice(const_iterator position, list&& x, const_iterator i);
|
| 123 |
-
void splice(const_iterator position, list& x,
|
| 124 |
-
|
| 125 |
-
void splice(const_iterator position, list&& x,
|
| 126 |
-
const_iterator first, const_iterator last);
|
| 127 |
|
| 128 |
-
|
| 129 |
-
template
|
| 130 |
|
| 131 |
-
|
| 132 |
template<class BinaryPredicate>
|
| 133 |
-
|
| 134 |
|
| 135 |
void merge(list& x);
|
| 136 |
void merge(list&& x);
|
| 137 |
template<class Compare> void merge(list& x, Compare comp);
|
| 138 |
template<class Compare> void merge(list&& x, Compare comp);
|
|
@@ -141,41 +135,27 @@ namespace std {
|
|
| 141 |
template<class Compare> void sort(Compare comp);
|
| 142 |
|
| 143 |
void reverse() noexcept;
|
| 144 |
};
|
| 145 |
|
| 146 |
-
template<class InputIterator,
|
| 147 |
-
class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
|
| 148 |
list(InputIterator, InputIterator, Allocator = Allocator())
|
| 149 |
-
-> list<
|
| 150 |
|
| 151 |
-
|
| 152 |
-
bool operator==(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 153 |
-
template <class T, class Allocator>
|
| 154 |
-
bool operator< (const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 155 |
-
template <class T, class Allocator>
|
| 156 |
-
bool operator!=(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 157 |
-
template <class T, class Allocator>
|
| 158 |
-
bool operator> (const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 159 |
-
template <class T, class Allocator>
|
| 160 |
-
bool operator>=(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 161 |
-
template <class T, class Allocator>
|
| 162 |
-
bool operator<=(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 163 |
-
|
| 164 |
-
// [list.special], specialized algorithms
|
| 165 |
template<class T, class Allocator>
|
| 166 |
void swap(list<T, Allocator>& x, list<T, Allocator>& y)
|
| 167 |
noexcept(noexcept(x.swap(y)));
|
| 168 |
}
|
| 169 |
```
|
| 170 |
|
| 171 |
An incomplete type `T` may be used when instantiating `list` if the
|
| 172 |
-
allocator
|
| 173 |
-
[[allocator.requirements.completeness]]
|
| 174 |
any member of the resulting specialization of `list` is referenced.
|
| 175 |
|
| 176 |
-
####
|
| 177 |
|
| 178 |
``` cpp
|
| 179 |
explicit list(const Allocator&);
|
| 180 |
```
|
| 181 |
|
|
@@ -185,26 +165,26 @@ explicit list(const Allocator&);
|
|
| 185 |
|
| 186 |
``` cpp
|
| 187 |
explicit list(size_type n, const Allocator& = Allocator());
|
| 188 |
```
|
| 189 |
|
|
|
|
|
|
|
| 190 |
*Effects:* Constructs a `list` with `n` default-inserted elements using
|
| 191 |
the specified allocator.
|
| 192 |
|
| 193 |
-
*Requires:* `T` shall be `DefaultInsertable` into `*this`.
|
| 194 |
-
|
| 195 |
*Complexity:* Linear in `n`.
|
| 196 |
|
| 197 |
``` cpp
|
| 198 |
list(size_type n, const T& value, const Allocator& = Allocator());
|
| 199 |
```
|
| 200 |
|
|
|
|
|
|
|
| 201 |
*Effects:* Constructs a `list` with `n` copies of `value`, using the
|
| 202 |
specified allocator.
|
| 203 |
|
| 204 |
-
*Requires:* `T` shall be `CopyInsertable` into `*this`.
|
| 205 |
-
|
| 206 |
*Complexity:* Linear in `n`.
|
| 207 |
|
| 208 |
``` cpp
|
| 209 |
template<class InputIterator>
|
| 210 |
list(InputIterator first, InputIterator last, const Allocator& = Allocator());
|
|
@@ -212,31 +192,33 @@ template <class InputIterator>
|
|
| 212 |
|
| 213 |
*Effects:* Constructs a `list` equal to the range \[`first`, `last`).
|
| 214 |
|
| 215 |
*Complexity:* Linear in `distance(first, last)`.
|
| 216 |
|
| 217 |
-
####
|
| 218 |
|
| 219 |
``` cpp
|
| 220 |
void resize(size_type sz);
|
| 221 |
```
|
| 222 |
|
|
|
|
|
|
|
| 223 |
*Effects:* If `size() < sz`, appends `sz - size()` default-inserted
|
| 224 |
elements to the sequence. If `sz <= size()`, equivalent to:
|
| 225 |
|
| 226 |
``` cpp
|
| 227 |
list<T>::iterator it = begin();
|
| 228 |
advance(it, sz);
|
| 229 |
erase(it, end());
|
| 230 |
```
|
| 231 |
|
| 232 |
-
*Requires:* `T` shall be `DefaultInsertable` into `*this`.
|
| 233 |
-
|
| 234 |
``` cpp
|
| 235 |
void resize(size_type sz, const T& c);
|
| 236 |
```
|
| 237 |
|
|
|
|
|
|
|
| 238 |
*Effects:* As if by:
|
| 239 |
|
| 240 |
``` cpp
|
| 241 |
if (sz > size())
|
| 242 |
insert(end(), sz-size(), c);
|
|
@@ -247,13 +229,11 @@ else if (sz < size()) {
|
|
| 247 |
}
|
| 248 |
else
|
| 249 |
; // do nothing
|
| 250 |
```
|
| 251 |
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
#### `list` modifiers <a id="list.modifiers">[[list.modifiers]]</a>
|
| 255 |
|
| 256 |
``` cpp
|
| 257 |
iterator insert(const_iterator position, const T& x);
|
| 258 |
iterator insert(const_iterator position, T&& x);
|
| 259 |
iterator insert(const_iterator position, size_type n, const T& x);
|
|
@@ -297,14 +277,18 @@ elements.
|
|
| 297 |
*Complexity:* Erasing a single element is a constant time operation with
|
| 298 |
a single call to the destructor of `T`. Erasing a range in a list is
|
| 299 |
linear time in the size of the range and the number of calls to the
|
| 300 |
destructor of type `T` is exactly equal to the size of the range.
|
| 301 |
|
| 302 |
-
####
|
| 303 |
|
| 304 |
Since lists allow fast insertion and erasing from the middle of a list,
|
| 305 |
-
certain operations are provided specifically for them.[^3]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 306 |
|
| 307 |
`list` provides three splice operations that destructively move elements
|
| 308 |
from one list to another. The behavior of splice operations is undefined
|
| 309 |
if `get_allocator() !=
|
| 310 |
x.get_allocator()`.
|
|
@@ -312,11 +296,11 @@ x.get_allocator()`.
|
|
| 312 |
``` cpp
|
| 313 |
void splice(const_iterator position, list& x);
|
| 314 |
void splice(const_iterator position, list&& x);
|
| 315 |
```
|
| 316 |
|
| 317 |
-
*
|
| 318 |
|
| 319 |
*Effects:* Inserts the contents of `x` before `position` and `x` becomes
|
| 320 |
empty. Pointers and references to the moved elements of `x` now refer to
|
| 321 |
those same elements but as members of `*this`. Iterators referring to
|
| 322 |
the moved elements will continue to refer to their elements, but they
|
|
@@ -329,11 +313,11 @@ now behave as iterators into `*this`, not into `x`.
|
|
| 329 |
``` cpp
|
| 330 |
void splice(const_iterator position, list& x, const_iterator i);
|
| 331 |
void splice(const_iterator position, list&& x, const_iterator i);
|
| 332 |
```
|
| 333 |
|
| 334 |
-
*
|
| 335 |
|
| 336 |
*Effects:* Inserts an element pointed to by `i` from list `x` before
|
| 337 |
`position` and removes the element from `x`. The result is unchanged if
|
| 338 |
`position == i` or `position == ++i`. Pointers and references to `*i`
|
| 339 |
continue to refer to this same element but as a member of `*this`.
|
|
@@ -349,55 +333,59 @@ void splice(const_iterator position, list& x, const_iterator first,
|
|
| 349 |
const_iterator last);
|
| 350 |
void splice(const_iterator position, list&& x, const_iterator first,
|
| 351 |
const_iterator last);
|
| 352 |
```
|
| 353 |
|
| 354 |
-
*
|
| 355 |
-
|
| 356 |
-
`last`).
|
| 357 |
|
| 358 |
*Effects:* Inserts elements in the range \[`first`, `last`) before
|
| 359 |
`position` and removes the elements from `x`. Pointers and references to
|
| 360 |
the moved elements of `x` now refer to those same elements but as
|
| 361 |
members of `*this`. Iterators referring to the moved elements will
|
| 362 |
continue to refer to their elements, but they now behave as iterators
|
| 363 |
into `*this`, not into `x`.
|
| 364 |
|
| 365 |
*Throws:* Nothing.
|
| 366 |
|
| 367 |
-
*Complexity:* Constant time if `
|
|
|
|
| 368 |
|
| 369 |
``` cpp
|
| 370 |
-
|
| 371 |
-
template
|
| 372 |
```
|
| 373 |
|
| 374 |
-
*Effects:* Erases all the elements in the list referred by a list
|
| 375 |
-
iterator `i` for which the following conditions hold:
|
| 376 |
-
`
|
| 377 |
-
|
|
|
|
|
|
|
| 378 |
|
| 379 |
*Throws:* Nothing unless an exception is thrown by `*i == value` or
|
| 380 |
`pred(*i) != false`.
|
| 381 |
|
| 382 |
-
*Remarks:* Stable
|
| 383 |
|
| 384 |
*Complexity:* Exactly `size()` applications of the corresponding
|
| 385 |
predicate.
|
| 386 |
|
| 387 |
``` cpp
|
| 388 |
-
|
| 389 |
-
template
|
| 390 |
```
|
| 391 |
|
| 392 |
*Effects:* Erases all but the first element from every consecutive group
|
| 393 |
of equal elements referred to by the iterator `i` in the range
|
| 394 |
\[`first + 1`, `last`) for which `*i == *(i-1)` (for the version of
|
| 395 |
`unique` with no arguments) or `pred(*i, *(i - 1))` (for the version of
|
| 396 |
`unique` with a predicate argument) holds. Invalidates only the
|
| 397 |
iterators and references to the erased elements.
|
| 398 |
|
|
|
|
|
|
|
| 399 |
*Throws:* Nothing unless an exception is thrown by `*i == *(i-1)` or
|
| 400 |
`pred(*i, *(i - 1))`
|
| 401 |
|
| 402 |
*Complexity:* If the range `[first, last)` is not empty, exactly
|
| 403 |
`(last - first) - 1` applications of the corresponding predicate,
|
|
@@ -408,33 +396,34 @@ void merge(list& x);
|
|
| 408 |
void merge(list&& x);
|
| 409 |
template<class Compare> void merge(list& x, Compare comp);
|
| 410 |
template<class Compare> void merge(list&& x, Compare comp);
|
| 411 |
```
|
| 412 |
|
| 413 |
-
*
|
| 414 |
-
|
| 415 |
-
|
|
|
|
| 416 |
|
| 417 |
-
*Effects:* If `(
|
| 418 |
-
sorted ranges `[begin(), end())` and `[x.begin(), x.end())`. The
|
| 419 |
-
is a range in which the elements will be sorted in non-decreasing
|
| 420 |
-
according to the ordering defined by `comp`; that is, for every
|
| 421 |
-
`i`, in the range other than the first, the condition
|
| 422 |
`comp(*i, *(i - 1))` will be `false`. Pointers and references to the
|
| 423 |
moved elements of `x` now refer to those same elements but as members of
|
| 424 |
`*this`. Iterators referring to the moved elements will continue to
|
| 425 |
refer to their elements, but they now behave as iterators into `*this`,
|
| 426 |
not into `x`.
|
| 427 |
|
| 428 |
-
*Remarks:* Stable
|
| 429 |
-
`[x.begin(), x.end())` is empty after the merge. No elements are
|
| 430 |
-
by this operation.
|
| 431 |
-
`get_allocator() != x.get_allocator()`.
|
| 432 |
|
| 433 |
*Complexity:* At most `size() + x.size() - 1` applications of `comp` if
|
| 434 |
-
`(
|
| 435 |
-
an exception is thrown other than by a comparison there
|
|
|
|
| 436 |
|
| 437 |
``` cpp
|
| 438 |
void reverse() noexcept;
|
| 439 |
```
|
| 440 |
|
|
@@ -446,27 +435,33 @@ affect the validity of iterators and references.
|
|
| 446 |
``` cpp
|
| 447 |
void sort();
|
| 448 |
template<class Compare> void sort(Compare comp);
|
| 449 |
```
|
| 450 |
|
| 451 |
-
*Requires:* `operator<` (for the first version) or `comp` (for the
|
| 452 |
-
second version) shall define a strict weak ordering ([[alg.sorting]]).
|
| 453 |
-
|
| 454 |
*Effects:* Sorts the list according to the `operator<` or a `Compare`
|
| 455 |
function object. If an exception is thrown, the order of the elements in
|
| 456 |
`*this` is unspecified. Does not affect the validity of iterators and
|
| 457 |
references.
|
| 458 |
|
| 459 |
-
*Remarks:* Stable
|
| 460 |
|
| 461 |
*Complexity:* Approximately N log N comparisons, where `N == size()`.
|
| 462 |
|
| 463 |
-
####
|
| 464 |
|
| 465 |
``` cpp
|
| 466 |
-
template
|
| 467 |
-
|
| 468 |
-
|
| 469 |
```
|
| 470 |
|
| 471 |
-
*Effects:*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 472 |
|
|
|
|
| 1 |
### Class template `list` <a id="list">[[list]]</a>
|
| 2 |
|
| 3 |
+
#### Overview <a id="list.overview">[[list.overview]]</a>
|
| 4 |
|
| 5 |
A `list` is a sequence container that supports bidirectional iterators
|
| 6 |
and allows constant time insert and erase operations anywhere within the
|
| 7 |
+
sequence, with storage management handled automatically. Unlike vectors
|
| 8 |
+
[[vector]] and deques [[deque]], fast random access to list elements is
|
| 9 |
+
not supported, but many algorithms only need sequential access anyway.
|
|
|
|
| 10 |
|
| 11 |
+
A `list` meets all of the requirements of a container, of a reversible
|
| 12 |
+
container (given in two tables in [[container.requirements]]), of a
|
| 13 |
+
sequence container, including most of the optional sequence container
|
| 14 |
+
requirements [[sequence.reqmts]], and of an allocator-aware container (
|
| 15 |
+
[[container.alloc.req]]). The exceptions are the `operator[]` and `at`
|
| 16 |
+
member functions, which are not provided.[^2] Descriptions are provided
|
| 17 |
+
here only for operations on `list` that are not described in one of
|
| 18 |
+
these tables or for operations where there is additional semantic
|
|
|
|
| 19 |
information.
|
| 20 |
|
| 21 |
``` cpp
|
| 22 |
namespace std {
|
| 23 |
template<class T, class Allocator = allocator<T>>
|
| 24 |
class list {
|
| 25 |
public:
|
| 26 |
+
// types
|
| 27 |
using value_type = T;
|
| 28 |
using allocator_type = Allocator;
|
| 29 |
using pointer = typename allocator_traits<Allocator>::pointer;
|
| 30 |
using const_pointer = typename allocator_traits<Allocator>::const_pointer;
|
| 31 |
using reference = value_type&;
|
|
|
|
| 58 |
void assign(InputIterator first, InputIterator last);
|
| 59 |
void assign(size_type n, const T& t);
|
| 60 |
void assign(initializer_list<T>);
|
| 61 |
allocator_type get_allocator() const noexcept;
|
| 62 |
|
| 63 |
+
// iterators
|
| 64 |
iterator begin() noexcept;
|
| 65 |
const_iterator begin() const noexcept;
|
| 66 |
iterator end() noexcept;
|
| 67 |
const_iterator end() const noexcept;
|
| 68 |
reverse_iterator rbegin() noexcept;
|
|
|
|
| 74 |
const_iterator cend() const noexcept;
|
| 75 |
const_reverse_iterator crbegin() const noexcept;
|
| 76 |
const_reverse_iterator crend() const noexcept;
|
| 77 |
|
| 78 |
// [list.capacity], capacity
|
| 79 |
+
[[nodiscard]] bool empty() const noexcept;
|
| 80 |
size_type size() const noexcept;
|
| 81 |
size_type max_size() const noexcept;
|
| 82 |
void resize(size_type sz);
|
| 83 |
void resize(size_type sz, const T& c);
|
| 84 |
|
| 85 |
+
// element access
|
| 86 |
reference front();
|
| 87 |
const_reference front() const;
|
| 88 |
reference back();
|
| 89 |
const_reference back() const;
|
| 90 |
|
|
|
|
| 101 |
template<class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 102 |
iterator insert(const_iterator position, const T& x);
|
| 103 |
iterator insert(const_iterator position, T&& x);
|
| 104 |
iterator insert(const_iterator position, size_type n, const T& x);
|
| 105 |
template<class InputIterator>
|
| 106 |
+
iterator insert(const_iterator position, InputIterator first, InputIterator last);
|
|
|
|
| 107 |
iterator insert(const_iterator position, initializer_list<T> il);
|
| 108 |
|
| 109 |
iterator erase(const_iterator position);
|
| 110 |
iterator erase(const_iterator position, const_iterator last);
|
| 111 |
+
void swap(list&) noexcept(allocator_traits<Allocator>::is_always_equal::value);
|
|
|
|
| 112 |
void clear() noexcept;
|
| 113 |
|
| 114 |
// [list.ops], list operations
|
| 115 |
void splice(const_iterator position, list& x);
|
| 116 |
void splice(const_iterator position, list&& x);
|
| 117 |
void splice(const_iterator position, list& x, const_iterator i);
|
| 118 |
void splice(const_iterator position, list&& x, const_iterator i);
|
| 119 |
+
void splice(const_iterator position, list& x, const_iterator first, const_iterator last);
|
| 120 |
+
void splice(const_iterator position, list&& x, const_iterator first, const_iterator last);
|
|
|
|
|
|
|
| 121 |
|
| 122 |
+
size_type remove(const T& value);
|
| 123 |
+
template<class Predicate> size_type remove_if(Predicate pred);
|
| 124 |
|
| 125 |
+
size_type unique();
|
| 126 |
template<class BinaryPredicate>
|
| 127 |
+
size_type unique(BinaryPredicate binary_pred);
|
| 128 |
|
| 129 |
void merge(list& x);
|
| 130 |
void merge(list&& x);
|
| 131 |
template<class Compare> void merge(list& x, Compare comp);
|
| 132 |
template<class Compare> void merge(list&& x, Compare comp);
|
|
|
|
| 135 |
template<class Compare> void sort(Compare comp);
|
| 136 |
|
| 137 |
void reverse() noexcept;
|
| 138 |
};
|
| 139 |
|
| 140 |
+
template<class InputIterator, class Allocator = allocator<iter-value-type<InputIterator>>>
|
|
|
|
| 141 |
list(InputIterator, InputIterator, Allocator = Allocator())
|
| 142 |
+
-> list<iter-value-type<InputIterator>, Allocator>;
|
| 143 |
|
| 144 |
+
// swap
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
template<class T, class Allocator>
|
| 146 |
void swap(list<T, Allocator>& x, list<T, Allocator>& y)
|
| 147 |
noexcept(noexcept(x.swap(y)));
|
| 148 |
}
|
| 149 |
```
|
| 150 |
|
| 151 |
An incomplete type `T` may be used when instantiating `list` if the
|
| 152 |
+
allocator meets the allocator completeness requirements
|
| 153 |
+
[[allocator.requirements.completeness]]. `T` shall be complete before
|
| 154 |
any member of the resulting specialization of `list` is referenced.
|
| 155 |
|
| 156 |
+
#### Constructors, copy, and assignment <a id="list.cons">[[list.cons]]</a>
|
| 157 |
|
| 158 |
``` cpp
|
| 159 |
explicit list(const Allocator&);
|
| 160 |
```
|
| 161 |
|
|
|
|
| 165 |
|
| 166 |
``` cpp
|
| 167 |
explicit list(size_type n, const Allocator& = Allocator());
|
| 168 |
```
|
| 169 |
|
| 170 |
+
*Preconditions:* `T` is *Cpp17DefaultInsertable* into `*this`.
|
| 171 |
+
|
| 172 |
*Effects:* Constructs a `list` with `n` default-inserted elements using
|
| 173 |
the specified allocator.
|
| 174 |
|
|
|
|
|
|
|
| 175 |
*Complexity:* Linear in `n`.
|
| 176 |
|
| 177 |
``` cpp
|
| 178 |
list(size_type n, const T& value, const Allocator& = Allocator());
|
| 179 |
```
|
| 180 |
|
| 181 |
+
*Preconditions:* `T` is *Cpp17CopyInsertable* into `*this`.
|
| 182 |
+
|
| 183 |
*Effects:* Constructs a `list` with `n` copies of `value`, using the
|
| 184 |
specified allocator.
|
| 185 |
|
|
|
|
|
|
|
| 186 |
*Complexity:* Linear in `n`.
|
| 187 |
|
| 188 |
``` cpp
|
| 189 |
template<class InputIterator>
|
| 190 |
list(InputIterator first, InputIterator last, const Allocator& = Allocator());
|
|
|
|
| 192 |
|
| 193 |
*Effects:* Constructs a `list` equal to the range \[`first`, `last`).
|
| 194 |
|
| 195 |
*Complexity:* Linear in `distance(first, last)`.
|
| 196 |
|
| 197 |
+
#### Capacity <a id="list.capacity">[[list.capacity]]</a>
|
| 198 |
|
| 199 |
``` cpp
|
| 200 |
void resize(size_type sz);
|
| 201 |
```
|
| 202 |
|
| 203 |
+
*Preconditions:* `T` is *Cpp17DefaultInsertable* into `*this`.
|
| 204 |
+
|
| 205 |
*Effects:* If `size() < sz`, appends `sz - size()` default-inserted
|
| 206 |
elements to the sequence. If `sz <= size()`, equivalent to:
|
| 207 |
|
| 208 |
``` cpp
|
| 209 |
list<T>::iterator it = begin();
|
| 210 |
advance(it, sz);
|
| 211 |
erase(it, end());
|
| 212 |
```
|
| 213 |
|
|
|
|
|
|
|
| 214 |
``` cpp
|
| 215 |
void resize(size_type sz, const T& c);
|
| 216 |
```
|
| 217 |
|
| 218 |
+
*Preconditions:* `T` is *Cpp17CopyInsertable* into `*this`.
|
| 219 |
+
|
| 220 |
*Effects:* As if by:
|
| 221 |
|
| 222 |
``` cpp
|
| 223 |
if (sz > size())
|
| 224 |
insert(end(), sz-size(), c);
|
|
|
|
| 229 |
}
|
| 230 |
else
|
| 231 |
; // do nothing
|
| 232 |
```
|
| 233 |
|
| 234 |
+
#### Modifiers <a id="list.modifiers">[[list.modifiers]]</a>
|
|
|
|
|
|
|
| 235 |
|
| 236 |
``` cpp
|
| 237 |
iterator insert(const_iterator position, const T& x);
|
| 238 |
iterator insert(const_iterator position, T&& x);
|
| 239 |
iterator insert(const_iterator position, size_type n, const T& x);
|
|
|
|
| 277 |
*Complexity:* Erasing a single element is a constant time operation with
|
| 278 |
a single call to the destructor of `T`. Erasing a range in a list is
|
| 279 |
linear time in the size of the range and the number of calls to the
|
| 280 |
destructor of type `T` is exactly equal to the size of the range.
|
| 281 |
|
| 282 |
+
#### Operations <a id="list.ops">[[list.ops]]</a>
|
| 283 |
|
| 284 |
Since lists allow fast insertion and erasing from the middle of a list,
|
| 285 |
+
certain operations are provided specifically for them.[^3] In this
|
| 286 |
+
subclause, arguments for a template parameter named `Predicate` or
|
| 287 |
+
`BinaryPredicate` shall meet the corresponding requirements in
|
| 288 |
+
[[algorithms.requirements]]. For `merge` and `sort`, the definitions and
|
| 289 |
+
requirements in [[alg.sorting]] apply.
|
| 290 |
|
| 291 |
`list` provides three splice operations that destructively move elements
|
| 292 |
from one list to another. The behavior of splice operations is undefined
|
| 293 |
if `get_allocator() !=
|
| 294 |
x.get_allocator()`.
|
|
|
|
| 296 |
``` cpp
|
| 297 |
void splice(const_iterator position, list& x);
|
| 298 |
void splice(const_iterator position, list&& x);
|
| 299 |
```
|
| 300 |
|
| 301 |
+
*Preconditions:* `addressof(x) != this` is `true`.
|
| 302 |
|
| 303 |
*Effects:* Inserts the contents of `x` before `position` and `x` becomes
|
| 304 |
empty. Pointers and references to the moved elements of `x` now refer to
|
| 305 |
those same elements but as members of `*this`. Iterators referring to
|
| 306 |
the moved elements will continue to refer to their elements, but they
|
|
|
|
| 313 |
``` cpp
|
| 314 |
void splice(const_iterator position, list& x, const_iterator i);
|
| 315 |
void splice(const_iterator position, list&& x, const_iterator i);
|
| 316 |
```
|
| 317 |
|
| 318 |
+
*Preconditions:* `i` is a valid dereferenceable iterator of `x`.
|
| 319 |
|
| 320 |
*Effects:* Inserts an element pointed to by `i` from list `x` before
|
| 321 |
`position` and removes the element from `x`. The result is unchanged if
|
| 322 |
`position == i` or `position == ++i`. Pointers and references to `*i`
|
| 323 |
continue to refer to this same element but as a member of `*this`.
|
|
|
|
| 333 |
const_iterator last);
|
| 334 |
void splice(const_iterator position, list&& x, const_iterator first,
|
| 335 |
const_iterator last);
|
| 336 |
```
|
| 337 |
|
| 338 |
+
*Preconditions:* `[first, last)` is a valid range in `x`. `position` is
|
| 339 |
+
not an iterator in the range \[`first`, `last`).
|
|
|
|
| 340 |
|
| 341 |
*Effects:* Inserts elements in the range \[`first`, `last`) before
|
| 342 |
`position` and removes the elements from `x`. Pointers and references to
|
| 343 |
the moved elements of `x` now refer to those same elements but as
|
| 344 |
members of `*this`. Iterators referring to the moved elements will
|
| 345 |
continue to refer to their elements, but they now behave as iterators
|
| 346 |
into `*this`, not into `x`.
|
| 347 |
|
| 348 |
*Throws:* Nothing.
|
| 349 |
|
| 350 |
+
*Complexity:* Constant time if `addressof(x) == this`; otherwise, linear
|
| 351 |
+
time.
|
| 352 |
|
| 353 |
``` cpp
|
| 354 |
+
size_type remove(const T& value);
|
| 355 |
+
template<class Predicate> size_type remove_if(Predicate pred);
|
| 356 |
```
|
| 357 |
|
| 358 |
+
*Effects:* Erases all the elements in the list referred to by a list
|
| 359 |
+
iterator `i` for which the following conditions hold: `*i == value`,
|
| 360 |
+
`pred(*i) != false`. Invalidates only the iterators and references to
|
| 361 |
+
the erased elements.
|
| 362 |
+
|
| 363 |
+
*Returns:* The number of elements erased.
|
| 364 |
|
| 365 |
*Throws:* Nothing unless an exception is thrown by `*i == value` or
|
| 366 |
`pred(*i) != false`.
|
| 367 |
|
| 368 |
+
*Remarks:* Stable [[algorithm.stable]].
|
| 369 |
|
| 370 |
*Complexity:* Exactly `size()` applications of the corresponding
|
| 371 |
predicate.
|
| 372 |
|
| 373 |
``` cpp
|
| 374 |
+
size_type unique();
|
| 375 |
+
template<class BinaryPredicate> size_type unique(BinaryPredicate binary_pred);
|
| 376 |
```
|
| 377 |
|
| 378 |
*Effects:* Erases all but the first element from every consecutive group
|
| 379 |
of equal elements referred to by the iterator `i` in the range
|
| 380 |
\[`first + 1`, `last`) for which `*i == *(i-1)` (for the version of
|
| 381 |
`unique` with no arguments) or `pred(*i, *(i - 1))` (for the version of
|
| 382 |
`unique` with a predicate argument) holds. Invalidates only the
|
| 383 |
iterators and references to the erased elements.
|
| 384 |
|
| 385 |
+
*Returns:* The number of elements erased.
|
| 386 |
+
|
| 387 |
*Throws:* Nothing unless an exception is thrown by `*i == *(i-1)` or
|
| 388 |
`pred(*i, *(i - 1))`
|
| 389 |
|
| 390 |
*Complexity:* If the range `[first, last)` is not empty, exactly
|
| 391 |
`(last - first) - 1` applications of the corresponding predicate,
|
|
|
|
| 396 |
void merge(list&& x);
|
| 397 |
template<class Compare> void merge(list& x, Compare comp);
|
| 398 |
template<class Compare> void merge(list&& x, Compare comp);
|
| 399 |
```
|
| 400 |
|
| 401 |
+
*Preconditions:* Both the list and the argument list shall be sorted
|
| 402 |
+
with respect to the comparator `operator<` (for the first two overloads)
|
| 403 |
+
or `comp` (for the last two overloads), and
|
| 404 |
+
`get_allocator() == x.get_allocator()` is `true`.
|
| 405 |
|
| 406 |
+
*Effects:* If `addressof(x) == this`, does nothing; otherwise, merges
|
| 407 |
+
the two sorted ranges `[begin(), end())` and `[x.begin(), x.end())`. The
|
| 408 |
+
result is a range in which the elements will be sorted in non-decreasing
|
| 409 |
+
order according to the ordering defined by `comp`; that is, for every
|
| 410 |
+
iterator `i`, in the range other than the first, the condition
|
| 411 |
`comp(*i, *(i - 1))` will be `false`. Pointers and references to the
|
| 412 |
moved elements of `x` now refer to those same elements but as members of
|
| 413 |
`*this`. Iterators referring to the moved elements will continue to
|
| 414 |
refer to their elements, but they now behave as iterators into `*this`,
|
| 415 |
not into `x`.
|
| 416 |
|
| 417 |
+
*Remarks:* Stable [[algorithm.stable]]. If `addressof(x) != this`, the
|
| 418 |
+
range `[x.begin(), x.end())` is empty after the merge. No elements are
|
| 419 |
+
copied by this operation.
|
|
|
|
| 420 |
|
| 421 |
*Complexity:* At most `size() + x.size() - 1` applications of `comp` if
|
| 422 |
+
`addressof(x) != this`; otherwise, no applications of `comp` are
|
| 423 |
+
performed. If an exception is thrown other than by a comparison there
|
| 424 |
+
are no effects.
|
| 425 |
|
| 426 |
``` cpp
|
| 427 |
void reverse() noexcept;
|
| 428 |
```
|
| 429 |
|
|
|
|
| 435 |
``` cpp
|
| 436 |
void sort();
|
| 437 |
template<class Compare> void sort(Compare comp);
|
| 438 |
```
|
| 439 |
|
|
|
|
|
|
|
|
|
|
| 440 |
*Effects:* Sorts the list according to the `operator<` or a `Compare`
|
| 441 |
function object. If an exception is thrown, the order of the elements in
|
| 442 |
`*this` is unspecified. Does not affect the validity of iterators and
|
| 443 |
references.
|
| 444 |
|
| 445 |
+
*Remarks:* Stable [[algorithm.stable]].
|
| 446 |
|
| 447 |
*Complexity:* Approximately N log N comparisons, where `N == size()`.
|
| 448 |
|
| 449 |
+
#### Erasure <a id="list.erasure">[[list.erasure]]</a>
|
| 450 |
|
| 451 |
``` cpp
|
| 452 |
+
template<class T, class Allocator, class U>
|
| 453 |
+
typename list<T, Allocator>::size_type
|
| 454 |
+
erase(list<T, Allocator>& c, const U& value);
|
| 455 |
```
|
| 456 |
|
| 457 |
+
*Effects:* Equivalent to:
|
| 458 |
+
`return erase_if(c, [&](auto& elem) { return elem == value; });`
|
| 459 |
+
|
| 460 |
+
``` cpp
|
| 461 |
+
template<class T, class Allocator, class Predicate>
|
| 462 |
+
typename list<T, Allocator>::size_type
|
| 463 |
+
erase_if(list<T, Allocator>& c, Predicate pred);
|
| 464 |
+
```
|
| 465 |
+
|
| 466 |
+
*Effects:* Equivalent to: `return c.remove_if(pred);`
|
| 467 |
|