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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Class template `forward_list` <a id="forward.list">[[forward.list]]</a>
|
| 2 |
+
|
| 3 |
+
#### Overview <a id="forward.list.overview">[[forward.list.overview]]</a>
|
| 4 |
+
|
| 5 |
+
A `forward_list` is a container that supports forward iterators and
|
| 6 |
+
allows constant time insert and erase operations anywhere within the
|
| 7 |
+
sequence, with storage management handled automatically. Fast random
|
| 8 |
+
access to list elements is not supported.
|
| 9 |
+
|
| 10 |
+
[*Note 1*: It is intended that `forward_list` have zero space or time
|
| 11 |
+
overhead relative to a hand-written C-style singly linked list. Features
|
| 12 |
+
that would conflict with that goal have been omitted. — *end note*]
|
| 13 |
+
|
| 14 |
+
A `forward_list` meets all of the requirements of a container
|
| 15 |
+
[[container.reqmts]], except that the `size()` member function is not
|
| 16 |
+
provided and `operator==` has linear complexity, A `forward_list` also
|
| 17 |
+
meets all of the requirements for an allocator-aware container
|
| 18 |
+
[[container.alloc.reqmts]]. In addition, a `forward_list` provides the
|
| 19 |
+
`assign` member functions and several of the optional sequence container
|
| 20 |
+
requirements [[sequence.reqmts]]. Descriptions are provided here only
|
| 21 |
+
for operations on `forward_list` that are not described in that table or
|
| 22 |
+
for operations where there is additional semantic information.
|
| 23 |
+
|
| 24 |
+
[*Note 2*: Modifying any list requires access to the element preceding
|
| 25 |
+
the first element of interest, but in a `forward_list` there is no
|
| 26 |
+
constant-time way to access a preceding element. For this reason,
|
| 27 |
+
`erase_after` and `splice_after` take fully-open ranges, not semi-open
|
| 28 |
+
ranges. — *end note*]
|
| 29 |
+
|
| 30 |
+
``` cpp
|
| 31 |
+
namespace std {
|
| 32 |
+
template<class T, class Allocator = allocator<T>>
|
| 33 |
+
class forward_list {
|
| 34 |
+
public:
|
| 35 |
+
// types
|
| 36 |
+
using value_type = T;
|
| 37 |
+
using allocator_type = Allocator;
|
| 38 |
+
using pointer = typename allocator_traits<Allocator>::pointer;
|
| 39 |
+
using const_pointer = typename allocator_traits<Allocator>::const_pointer;
|
| 40 |
+
using reference = value_type&;
|
| 41 |
+
using const_reference = const value_type&;
|
| 42 |
+
using size_type = implementation-defined // type of forward_list::size_type; // see [container.requirements]
|
| 43 |
+
using difference_type = implementation-defined // type of forward_list::difference_type; // see [container.requirements]
|
| 44 |
+
using iterator = implementation-defined // type of forward_list::iterator; // see [container.requirements]
|
| 45 |
+
using const_iterator = implementation-defined // type of forward_list::const_iterator; // see [container.requirements]
|
| 46 |
+
|
| 47 |
+
// [forward.list.cons], construct/copy/destroy
|
| 48 |
+
forward_list() : forward_list(Allocator()) { }
|
| 49 |
+
explicit forward_list(const Allocator&);
|
| 50 |
+
explicit forward_list(size_type n, const Allocator& = Allocator());
|
| 51 |
+
forward_list(size_type n, const T& value, const Allocator& = Allocator());
|
| 52 |
+
template<class InputIterator>
|
| 53 |
+
forward_list(InputIterator first, InputIterator last, const Allocator& = Allocator());
|
| 54 |
+
template<container-compatible-range<T> R>
|
| 55 |
+
forward_list(from_range_t, R&& rg, const Allocator& = Allocator());
|
| 56 |
+
forward_list(const forward_list& x);
|
| 57 |
+
forward_list(forward_list&& x);
|
| 58 |
+
forward_list(const forward_list& x, const type_identity_t<Allocator>&);
|
| 59 |
+
forward_list(forward_list&& x, const type_identity_t<Allocator>&);
|
| 60 |
+
forward_list(initializer_list<T>, const Allocator& = Allocator());
|
| 61 |
+
~forward_list();
|
| 62 |
+
forward_list& operator=(const forward_list& x);
|
| 63 |
+
forward_list& operator=(forward_list&& x)
|
| 64 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value);
|
| 65 |
+
forward_list& operator=(initializer_list<T>);
|
| 66 |
+
template<class InputIterator>
|
| 67 |
+
void assign(InputIterator first, InputIterator last);
|
| 68 |
+
template<container-compatible-range<T> R>
|
| 69 |
+
void assign_range(R&& rg);
|
| 70 |
+
void assign(size_type n, const T& t);
|
| 71 |
+
void assign(initializer_list<T>);
|
| 72 |
+
allocator_type get_allocator() const noexcept;
|
| 73 |
+
|
| 74 |
+
// [forward.list.iter], iterators
|
| 75 |
+
iterator before_begin() noexcept;
|
| 76 |
+
const_iterator before_begin() const noexcept;
|
| 77 |
+
iterator begin() noexcept;
|
| 78 |
+
const_iterator begin() const noexcept;
|
| 79 |
+
iterator end() noexcept;
|
| 80 |
+
const_iterator end() const noexcept;
|
| 81 |
+
|
| 82 |
+
const_iterator cbegin() const noexcept;
|
| 83 |
+
const_iterator cbefore_begin() const noexcept;
|
| 84 |
+
const_iterator cend() const noexcept;
|
| 85 |
+
|
| 86 |
+
// capacity
|
| 87 |
+
[[nodiscard]] bool empty() const noexcept;
|
| 88 |
+
size_type max_size() const noexcept;
|
| 89 |
+
|
| 90 |
+
// [forward.list.access], element access
|
| 91 |
+
reference front();
|
| 92 |
+
const_reference front() const;
|
| 93 |
+
|
| 94 |
+
// [forward.list.modifiers], modifiers
|
| 95 |
+
template<class... Args> reference emplace_front(Args&&... args);
|
| 96 |
+
void push_front(const T& x);
|
| 97 |
+
void push_front(T&& x);
|
| 98 |
+
template<container-compatible-range<T> R>
|
| 99 |
+
void prepend_range(R&& rg);
|
| 100 |
+
void pop_front();
|
| 101 |
+
|
| 102 |
+
template<class... Args> iterator emplace_after(const_iterator position, Args&&... args);
|
| 103 |
+
iterator insert_after(const_iterator position, const T& x);
|
| 104 |
+
iterator insert_after(const_iterator position, T&& x);
|
| 105 |
+
|
| 106 |
+
iterator insert_after(const_iterator position, size_type n, const T& x);
|
| 107 |
+
template<class InputIterator>
|
| 108 |
+
iterator insert_after(const_iterator position, InputIterator first, InputIterator last);
|
| 109 |
+
iterator insert_after(const_iterator position, initializer_list<T> il);
|
| 110 |
+
template<container-compatible-range<T> R>
|
| 111 |
+
iterator insert_range_after(const_iterator position, R&& rg);
|
| 112 |
+
|
| 113 |
+
iterator erase_after(const_iterator position);
|
| 114 |
+
iterator erase_after(const_iterator position, const_iterator last);
|
| 115 |
+
void swap(forward_list&)
|
| 116 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value);
|
| 117 |
+
|
| 118 |
+
void resize(size_type sz);
|
| 119 |
+
void resize(size_type sz, const value_type& c);
|
| 120 |
+
void clear() noexcept;
|
| 121 |
+
|
| 122 |
+
// [forward.list.ops], forward_list operations
|
| 123 |
+
void splice_after(const_iterator position, forward_list& x);
|
| 124 |
+
void splice_after(const_iterator position, forward_list&& x);
|
| 125 |
+
void splice_after(const_iterator position, forward_list& x, const_iterator i);
|
| 126 |
+
void splice_after(const_iterator position, forward_list&& x, const_iterator i);
|
| 127 |
+
void splice_after(const_iterator position, forward_list& x,
|
| 128 |
+
const_iterator first, const_iterator last);
|
| 129 |
+
void splice_after(const_iterator position, forward_list&& x,
|
| 130 |
+
const_iterator first, const_iterator last);
|
| 131 |
+
|
| 132 |
+
size_type remove(const T& value);
|
| 133 |
+
template<class Predicate> size_type remove_if(Predicate pred);
|
| 134 |
+
|
| 135 |
+
size_type unique();
|
| 136 |
+
template<class BinaryPredicate> size_type unique(BinaryPredicate binary_pred);
|
| 137 |
+
|
| 138 |
+
void merge(forward_list& x);
|
| 139 |
+
void merge(forward_list&& x);
|
| 140 |
+
template<class Compare> void merge(forward_list& x, Compare comp);
|
| 141 |
+
template<class Compare> void merge(forward_list&& x, Compare comp);
|
| 142 |
+
|
| 143 |
+
void sort();
|
| 144 |
+
template<class Compare> void sort(Compare comp);
|
| 145 |
+
|
| 146 |
+
void reverse() noexcept;
|
| 147 |
+
};
|
| 148 |
+
|
| 149 |
+
template<class InputIterator, class Allocator = allocator<iter-value-type<InputIterator>>>
|
| 150 |
+
forward_list(InputIterator, InputIterator, Allocator = Allocator())
|
| 151 |
+
-> forward_list<iter-value-type<InputIterator>, Allocator>;
|
| 152 |
+
|
| 153 |
+
template<ranges::input_range R, class Allocator = allocator<ranges::range_value_t<R>>>
|
| 154 |
+
forward_list(from_range_t, R&&, Allocator = Allocator())
|
| 155 |
+
-> forward_list<ranges::range_value_t<R>, Allocator>;
|
| 156 |
+
}
|
| 157 |
+
```
|
| 158 |
+
|
| 159 |
+
An incomplete type `T` may be used when instantiating `forward_list` if
|
| 160 |
+
the allocator meets the allocator completeness requirements
|
| 161 |
+
[[allocator.requirements.completeness]]. `T` shall be complete before
|
| 162 |
+
any member of the resulting specialization of `forward_list` is
|
| 163 |
+
referenced.
|
| 164 |
+
|
| 165 |
+
#### Constructors, copy, and assignment <a id="forward.list.cons">[[forward.list.cons]]</a>
|
| 166 |
+
|
| 167 |
+
``` cpp
|
| 168 |
+
explicit forward_list(const Allocator&);
|
| 169 |
+
```
|
| 170 |
+
|
| 171 |
+
*Effects:* Constructs an empty `forward_list` object using the specified
|
| 172 |
+
allocator.
|
| 173 |
+
|
| 174 |
+
*Complexity:* Constant.
|
| 175 |
+
|
| 176 |
+
``` cpp
|
| 177 |
+
explicit forward_list(size_type n, const Allocator& = Allocator());
|
| 178 |
+
```
|
| 179 |
+
|
| 180 |
+
*Preconditions:* `T` is *Cpp17DefaultInsertable* into `*this`.
|
| 181 |
+
|
| 182 |
+
*Effects:* Constructs a `forward_list` object with `n` default-inserted
|
| 183 |
+
elements using the specified allocator.
|
| 184 |
+
|
| 185 |
+
*Complexity:* Linear in `n`.
|
| 186 |
+
|
| 187 |
+
``` cpp
|
| 188 |
+
forward_list(size_type n, const T& value, const Allocator& = Allocator());
|
| 189 |
+
```
|
| 190 |
+
|
| 191 |
+
*Preconditions:* `T` is *Cpp17CopyInsertable* into `*this`.
|
| 192 |
+
|
| 193 |
+
*Effects:* Constructs a `forward_list` object with `n` copies of `value`
|
| 194 |
+
using the specified allocator.
|
| 195 |
+
|
| 196 |
+
*Complexity:* Linear in `n`.
|
| 197 |
+
|
| 198 |
+
``` cpp
|
| 199 |
+
template<class InputIterator>
|
| 200 |
+
forward_list(InputIterator first, InputIterator last, const Allocator& = Allocator());
|
| 201 |
+
```
|
| 202 |
+
|
| 203 |
+
*Effects:* Constructs a `forward_list` object equal to the range
|
| 204 |
+
\[`first`, `last`).
|
| 205 |
+
|
| 206 |
+
*Complexity:* Linear in `distance(first, last)`.
|
| 207 |
+
|
| 208 |
+
``` cpp
|
| 209 |
+
template<container-compatible-range<T> R>
|
| 210 |
+
forward_list(from_range_t, R&& rg, const Allocator& = Allocator());
|
| 211 |
+
```
|
| 212 |
+
|
| 213 |
+
*Effects:* Constructs a `forward_list` object with the elements of the
|
| 214 |
+
range `rg`.
|
| 215 |
+
|
| 216 |
+
*Complexity:* Linear in `ranges::distance(rg)`.
|
| 217 |
+
|
| 218 |
+
#### Iterators <a id="forward.list.iter">[[forward.list.iter]]</a>
|
| 219 |
+
|
| 220 |
+
``` cpp
|
| 221 |
+
iterator before_begin() noexcept;
|
| 222 |
+
const_iterator before_begin() const noexcept;
|
| 223 |
+
const_iterator cbefore_begin() const noexcept;
|
| 224 |
+
```
|
| 225 |
+
|
| 226 |
+
*Effects:* `cbefore_begin()` is equivalent to
|
| 227 |
+
`const_cast<forward_list const&>(*this).before_begin()`.
|
| 228 |
+
|
| 229 |
+
*Returns:* A non-dereferenceable iterator that, when incremented, is
|
| 230 |
+
equal to the iterator returned by `begin()`.
|
| 231 |
+
|
| 232 |
+
*Remarks:* `before_begin() == end()` shall equal `false`.
|
| 233 |
+
|
| 234 |
+
#### Element access <a id="forward.list.access">[[forward.list.access]]</a>
|
| 235 |
+
|
| 236 |
+
``` cpp
|
| 237 |
+
reference front();
|
| 238 |
+
const_reference front() const;
|
| 239 |
+
```
|
| 240 |
+
|
| 241 |
+
*Returns:* `*begin()`
|
| 242 |
+
|
| 243 |
+
#### Modifiers <a id="forward.list.modifiers">[[forward.list.modifiers]]</a>
|
| 244 |
+
|
| 245 |
+
None of the overloads of `insert_after` shall affect the validity of
|
| 246 |
+
iterators and references, and `erase_after` shall invalidate only
|
| 247 |
+
iterators and references to the erased elements. If an exception is
|
| 248 |
+
thrown during `insert_after` there shall be no effect. Inserting `n`
|
| 249 |
+
elements into a `forward_list` is linear in `n`, and the number of calls
|
| 250 |
+
to the copy or move constructor of `T` is exactly equal to `n`. Erasing
|
| 251 |
+
`n` elements from a `forward_list` is linear in `n` and the number of
|
| 252 |
+
calls to the destructor of type `T` is exactly equal to `n`.
|
| 253 |
+
|
| 254 |
+
``` cpp
|
| 255 |
+
template<class... Args> reference emplace_front(Args&&... args);
|
| 256 |
+
```
|
| 257 |
+
|
| 258 |
+
*Effects:* Inserts an object of type `value_type` constructed with
|
| 259 |
+
`value_type(std::forward<Args>(args)...)` at the beginning of the list.
|
| 260 |
+
|
| 261 |
+
``` cpp
|
| 262 |
+
void push_front(const T& x);
|
| 263 |
+
void push_front(T&& x);
|
| 264 |
+
```
|
| 265 |
+
|
| 266 |
+
*Effects:* Inserts a copy of `x` at the beginning of the list.
|
| 267 |
+
|
| 268 |
+
``` cpp
|
| 269 |
+
template<container-compatible-range<T> R>
|
| 270 |
+
void prepend_range(R&& rg);
|
| 271 |
+
```
|
| 272 |
+
|
| 273 |
+
*Effects:* Inserts a copy of each element of `rg` at the beginning of
|
| 274 |
+
the list.
|
| 275 |
+
|
| 276 |
+
[*Note 1*: The order of elements is not reversed. — *end note*]
|
| 277 |
+
|
| 278 |
+
``` cpp
|
| 279 |
+
void pop_front();
|
| 280 |
+
```
|
| 281 |
+
|
| 282 |
+
*Effects:* As if by `erase_after(before_begin())`.
|
| 283 |
+
|
| 284 |
+
``` cpp
|
| 285 |
+
iterator insert_after(const_iterator position, const T& x);
|
| 286 |
+
```
|
| 287 |
+
|
| 288 |
+
*Preconditions:* `T` is *Cpp17CopyInsertable* into `forward_list`.
|
| 289 |
+
`position` is `before_begin()` or is a dereferenceable iterator in the
|
| 290 |
+
range \[`begin()`, `end()`).
|
| 291 |
+
|
| 292 |
+
*Effects:* Inserts a copy of `x` after `position`.
|
| 293 |
+
|
| 294 |
+
*Returns:* An iterator pointing to the copy of `x`.
|
| 295 |
+
|
| 296 |
+
``` cpp
|
| 297 |
+
iterator insert_after(const_iterator position, T&& x);
|
| 298 |
+
```
|
| 299 |
+
|
| 300 |
+
*Preconditions:* `T` is *Cpp17MoveInsertable* into `forward_list`.
|
| 301 |
+
`position` is `before_begin()` or is a dereferenceable iterator in the
|
| 302 |
+
range \[`begin()`, `end()`).
|
| 303 |
+
|
| 304 |
+
*Effects:* Inserts a copy of `x` after `position`.
|
| 305 |
+
|
| 306 |
+
*Returns:* An iterator pointing to the copy of `x`.
|
| 307 |
+
|
| 308 |
+
``` cpp
|
| 309 |
+
iterator insert_after(const_iterator position, size_type n, const T& x);
|
| 310 |
+
```
|
| 311 |
+
|
| 312 |
+
*Preconditions:* `T` is *Cpp17CopyInsertable* into `forward_list`.
|
| 313 |
+
`position` is `before_begin()` or is a dereferenceable iterator in the
|
| 314 |
+
range \[`begin()`, `end()`).
|
| 315 |
+
|
| 316 |
+
*Effects:* Inserts `n` copies of `x` after `position`.
|
| 317 |
+
|
| 318 |
+
*Returns:* An iterator pointing to the last inserted copy of `x`, or
|
| 319 |
+
`position` if `n == 0` is `true`.
|
| 320 |
+
|
| 321 |
+
``` cpp
|
| 322 |
+
template<class InputIterator>
|
| 323 |
+
iterator insert_after(const_iterator position, InputIterator first, InputIterator last);
|
| 324 |
+
```
|
| 325 |
+
|
| 326 |
+
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `forward_list`
|
| 327 |
+
from `*first`. `position` is `before_begin()` or is a dereferenceable
|
| 328 |
+
iterator in the range \[`begin()`, `end()`). Neither `first` nor `last`
|
| 329 |
+
are iterators in `*this`.
|
| 330 |
+
|
| 331 |
+
*Effects:* Inserts copies of elements in \[`first`, `last`) after
|
| 332 |
+
`position`.
|
| 333 |
+
|
| 334 |
+
*Returns:* An iterator pointing to the last inserted element, or
|
| 335 |
+
`position` if `first == last` is `true`.
|
| 336 |
+
|
| 337 |
+
``` cpp
|
| 338 |
+
template<container-compatible-range<T> R>
|
| 339 |
+
iterator insert_range_after(const_iterator position, R&& rg);
|
| 340 |
+
```
|
| 341 |
+
|
| 342 |
+
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `forward_list`
|
| 343 |
+
from `*ranges::begin(rg)`. `position` is `before_begin()` or is a
|
| 344 |
+
dereferenceable iterator in the range \[`begin()`, `end()`). `rg` and
|
| 345 |
+
`*this` do not overlap.
|
| 346 |
+
|
| 347 |
+
*Effects:* Inserts copies of elements in the range `rg` after
|
| 348 |
+
`position`.
|
| 349 |
+
|
| 350 |
+
*Returns:* An iterator pointing to the last inserted element, or
|
| 351 |
+
`position` if `rg` is empty.
|
| 352 |
+
|
| 353 |
+
``` cpp
|
| 354 |
+
iterator insert_after(const_iterator position, initializer_list<T> il);
|
| 355 |
+
```
|
| 356 |
+
|
| 357 |
+
*Effects:* Equivalent to:
|
| 358 |
+
`return insert_after(position, il.begin(), il.end());`
|
| 359 |
+
|
| 360 |
+
``` cpp
|
| 361 |
+
template<class... Args>
|
| 362 |
+
iterator emplace_after(const_iterator position, Args&&... args);
|
| 363 |
+
```
|
| 364 |
+
|
| 365 |
+
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `forward_list`
|
| 366 |
+
from `std::forward<Args>(args)...`. `position` is `before_begin()` or is
|
| 367 |
+
a dereferenceable iterator in the range \[`begin()`, `end()`).
|
| 368 |
+
|
| 369 |
+
*Effects:* Inserts an object of type `value_type`
|
| 370 |
+
direct-non-list-initialized with `std::forward<Args>(args)...` after
|
| 371 |
+
`position`.
|
| 372 |
+
|
| 373 |
+
*Returns:* An iterator pointing to the new object.
|
| 374 |
+
|
| 375 |
+
``` cpp
|
| 376 |
+
iterator erase_after(const_iterator position);
|
| 377 |
+
```
|
| 378 |
+
|
| 379 |
+
*Preconditions:* The iterator following `position` is dereferenceable.
|
| 380 |
+
|
| 381 |
+
*Effects:* Erases the element pointed to by the iterator following
|
| 382 |
+
`position`.
|
| 383 |
+
|
| 384 |
+
*Returns:* An iterator pointing to the element following the one that
|
| 385 |
+
was erased, or `end()` if no such element exists.
|
| 386 |
+
|
| 387 |
+
*Throws:* Nothing.
|
| 388 |
+
|
| 389 |
+
``` cpp
|
| 390 |
+
iterator erase_after(const_iterator position, const_iterator last);
|
| 391 |
+
```
|
| 392 |
+
|
| 393 |
+
*Preconditions:* All iterators in the range (`position`, `last`) are
|
| 394 |
+
dereferenceable.
|
| 395 |
+
|
| 396 |
+
*Effects:* Erases the elements in the range (`position`, `last`).
|
| 397 |
+
|
| 398 |
+
*Returns:* `last`.
|
| 399 |
+
|
| 400 |
+
*Throws:* Nothing.
|
| 401 |
+
|
| 402 |
+
``` cpp
|
| 403 |
+
void resize(size_type sz);
|
| 404 |
+
```
|
| 405 |
+
|
| 406 |
+
*Preconditions:* `T` is *Cpp17DefaultInsertable* into `*this`.
|
| 407 |
+
|
| 408 |
+
*Effects:* If `sz < distance(begin(), end())`, erases the last
|
| 409 |
+
`distance(begin(), end()) - sz` elements from the list. Otherwise,
|
| 410 |
+
inserts `sz - distance(begin(), end())` default-inserted elements at the
|
| 411 |
+
end of the list.
|
| 412 |
+
|
| 413 |
+
``` cpp
|
| 414 |
+
void resize(size_type sz, const value_type& c);
|
| 415 |
+
```
|
| 416 |
+
|
| 417 |
+
*Preconditions:* `T` is *Cpp17CopyInsertable* into `*this`.
|
| 418 |
+
|
| 419 |
+
*Effects:* If `sz < distance(begin(), end())`, erases the last
|
| 420 |
+
`distance(begin(), end()) - sz` elements from the list. Otherwise,
|
| 421 |
+
inserts `sz - distance(begin(), end())` copies of `c` at the end of the
|
| 422 |
+
list.
|
| 423 |
+
|
| 424 |
+
``` cpp
|
| 425 |
+
void clear() noexcept;
|
| 426 |
+
```
|
| 427 |
+
|
| 428 |
+
*Effects:* Erases all elements in the range \[`begin()`, `end()`).
|
| 429 |
+
|
| 430 |
+
*Remarks:* Does not invalidate past-the-end iterators.
|
| 431 |
+
|
| 432 |
+
#### Operations <a id="forward.list.ops">[[forward.list.ops]]</a>
|
| 433 |
+
|
| 434 |
+
In this subclause, arguments for a template parameter named `Predicate`
|
| 435 |
+
or `BinaryPredicate` shall meet the corresponding requirements in
|
| 436 |
+
[[algorithms.requirements]]. The semantics of `i + n`, where `i` is an
|
| 437 |
+
iterator into the list and `n` is an integer, are the same as those of
|
| 438 |
+
`next(i, n)`. The expression `i - n`, where `i` is an iterator into the
|
| 439 |
+
list and `n` is an integer, means an iterator `j` such that `j + n == i`
|
| 440 |
+
is `true`. For `merge` and `sort`, the definitions and requirements in
|
| 441 |
+
[[alg.sorting]] apply.
|
| 442 |
+
|
| 443 |
+
``` cpp
|
| 444 |
+
void splice_after(const_iterator position, forward_list& x);
|
| 445 |
+
void splice_after(const_iterator position, forward_list&& x);
|
| 446 |
+
```
|
| 447 |
+
|
| 448 |
+
*Preconditions:* `position` is `before_begin()` or is a dereferenceable
|
| 449 |
+
iterator in the range \[`begin()`, `end()`).
|
| 450 |
+
`get_allocator() == x.get_allocator()` is `true`. `addressof(x) != this`
|
| 451 |
+
is `true`.
|
| 452 |
+
|
| 453 |
+
*Effects:* Inserts the contents of `x` after `position`, and `x` becomes
|
| 454 |
+
empty. Pointers and references to the moved elements of `x` now refer to
|
| 455 |
+
those same elements but as members of `*this`. Iterators referring to
|
| 456 |
+
the moved elements will continue to refer to their elements, but they
|
| 457 |
+
now behave as iterators into `*this`, not into `x`.
|
| 458 |
+
|
| 459 |
+
*Throws:* Nothing.
|
| 460 |
+
|
| 461 |
+
*Complexity:* 𝑂(`distance(x.begin(), x.end())`)
|
| 462 |
+
|
| 463 |
+
``` cpp
|
| 464 |
+
void splice_after(const_iterator position, forward_list& x, const_iterator i);
|
| 465 |
+
void splice_after(const_iterator position, forward_list&& x, const_iterator i);
|
| 466 |
+
```
|
| 467 |
+
|
| 468 |
+
*Preconditions:* `position` is `before_begin()` or is a dereferenceable
|
| 469 |
+
iterator in the range \[`begin()`, `end()`). The iterator following `i`
|
| 470 |
+
is a dereferenceable iterator in `x`.
|
| 471 |
+
`get_allocator() == x.get_allocator()` is `true`.
|
| 472 |
+
|
| 473 |
+
*Effects:* Inserts the element following `i` into `*this`, following
|
| 474 |
+
`position`, and removes it from `x`. The result is unchanged if
|
| 475 |
+
`position == i` or `position == ++i`. Pointers and references to `*++i`
|
| 476 |
+
continue to refer to the same element but as a member of `*this`.
|
| 477 |
+
Iterators to `*++i` continue to refer to the same element, but now
|
| 478 |
+
behave as iterators into `*this`, not into `x`.
|
| 479 |
+
|
| 480 |
+
*Throws:* Nothing.
|
| 481 |
+
|
| 482 |
+
*Complexity:* 𝑂(1)
|
| 483 |
+
|
| 484 |
+
``` cpp
|
| 485 |
+
void splice_after(const_iterator position, forward_list& x,
|
| 486 |
+
const_iterator first, const_iterator last);
|
| 487 |
+
void splice_after(const_iterator position, forward_list&& x,
|
| 488 |
+
const_iterator first, const_iterator last);
|
| 489 |
+
```
|
| 490 |
+
|
| 491 |
+
*Preconditions:* `position` is `before_begin()` or is a dereferenceable
|
| 492 |
+
iterator in the range \[`begin()`, `end()`). (`first`, `last`) is a
|
| 493 |
+
valid range in `x`, and all iterators in the range (`first`, `last`) are
|
| 494 |
+
dereferenceable. `position` is not an iterator in the range (`first`,
|
| 495 |
+
`last`). `get_allocator() == x.get_allocator()` is `true`.
|
| 496 |
+
|
| 497 |
+
*Effects:* Inserts elements in the range (`first`, `last`) after
|
| 498 |
+
`position` and removes the elements from `x`. Pointers and references to
|
| 499 |
+
the moved elements of `x` now refer to those same elements but as
|
| 500 |
+
members of `*this`. Iterators referring to the moved elements will
|
| 501 |
+
continue to refer to their elements, but they now behave as iterators
|
| 502 |
+
into `*this`, not into `x`.
|
| 503 |
+
|
| 504 |
+
*Complexity:* 𝑂(`distance(first, last)`)
|
| 505 |
+
|
| 506 |
+
``` cpp
|
| 507 |
+
size_type remove(const T& value);
|
| 508 |
+
template<class Predicate> size_type remove_if(Predicate pred);
|
| 509 |
+
```
|
| 510 |
+
|
| 511 |
+
*Effects:* Erases all the elements in the list referred to by a list
|
| 512 |
+
iterator `i` for which the following conditions hold: `*i == value` (for
|
| 513 |
+
`remove()`), `pred(*i)` is `true` (for `remove_if()`). Invalidates only
|
| 514 |
+
the iterators and references to the erased elements.
|
| 515 |
+
|
| 516 |
+
*Returns:* The number of elements erased.
|
| 517 |
+
|
| 518 |
+
*Throws:* Nothing unless an exception is thrown by the equality
|
| 519 |
+
comparison or the predicate.
|
| 520 |
+
|
| 521 |
+
*Complexity:* Exactly `distance(begin(), end())` applications of the
|
| 522 |
+
corresponding predicate.
|
| 523 |
+
|
| 524 |
+
*Remarks:* Stable [[algorithm.stable]].
|
| 525 |
+
|
| 526 |
+
``` cpp
|
| 527 |
+
size_type unique();
|
| 528 |
+
template<class BinaryPredicate> size_type unique(BinaryPredicate binary_pred);
|
| 529 |
+
```
|
| 530 |
+
|
| 531 |
+
Let `binary_pred` be `equal_to<>{}` for the first overload.
|
| 532 |
+
|
| 533 |
+
*Preconditions:* `binary_pred` is an equivalence relation.
|
| 534 |
+
|
| 535 |
+
*Effects:* Erases all but the first element from every consecutive group
|
| 536 |
+
of equivalent elements. That is, for a nonempty list, erases all
|
| 537 |
+
elements referred to by the iterator `i` in the range \[`begin() + 1`,
|
| 538 |
+
`end()`) for which `binary_pred(*i, *(i - 1))` is `true`. Invalidates
|
| 539 |
+
only the iterators and references to the erased elements.
|
| 540 |
+
|
| 541 |
+
*Returns:* The number of elements erased.
|
| 542 |
+
|
| 543 |
+
*Throws:* Nothing unless an exception is thrown by the predicate.
|
| 544 |
+
|
| 545 |
+
*Complexity:* If `empty()` is `false`, exactly
|
| 546 |
+
`distance(begin(), end()) - 1` applications of the corresponding
|
| 547 |
+
predicate, otherwise no applications of the predicate.
|
| 548 |
+
|
| 549 |
+
``` cpp
|
| 550 |
+
void merge(forward_list& x);
|
| 551 |
+
void merge(forward_list&& x);
|
| 552 |
+
template<class Compare> void merge(forward_list& x, Compare comp);
|
| 553 |
+
template<class Compare> void merge(forward_list&& x, Compare comp);
|
| 554 |
+
```
|
| 555 |
+
|
| 556 |
+
Let `comp` be `less<>` for the first two overloads.
|
| 557 |
+
|
| 558 |
+
*Preconditions:* `*this` and `x` are both sorted with respect to the
|
| 559 |
+
comparator `comp`, and `get_allocator() == x.get_allocator()` is `true`.
|
| 560 |
+
|
| 561 |
+
*Effects:* If `addressof(x) == this`, there are no effects. Otherwise,
|
| 562 |
+
merges the two sorted ranges \[`begin()`, `end()`) and \[`x.begin()`,
|
| 563 |
+
`x.end()`). The result is a range that is sorted with respect to the
|
| 564 |
+
comparator `comp`. Pointers and references to the moved elements of `x`
|
| 565 |
+
now refer to those same elements but as members of `*this`. Iterators
|
| 566 |
+
referring to the moved elements will continue to refer to their
|
| 567 |
+
elements, but they now behave as iterators into `*this`, not into `x`.
|
| 568 |
+
|
| 569 |
+
*Complexity:* At most
|
| 570 |
+
`distance(begin(), end()) + distance(x.begin(), x.end()) - 1`
|
| 571 |
+
comparisons if `addressof(x) != this`; otherwise, no comparisons are
|
| 572 |
+
performed.
|
| 573 |
+
|
| 574 |
+
*Remarks:* Stable [[algorithm.stable]]. If `addressof(x) != this`, `x`
|
| 575 |
+
is empty after the merge. No elements are copied by this operation. If
|
| 576 |
+
an exception is thrown other than by a comparison, there are no effects.
|
| 577 |
+
|
| 578 |
+
``` cpp
|
| 579 |
+
void sort();
|
| 580 |
+
template<class Compare> void sort(Compare comp);
|
| 581 |
+
```
|
| 582 |
+
|
| 583 |
+
*Effects:* Sorts the list according to the `operator<` or the `comp`
|
| 584 |
+
function object. If an exception is thrown, the order of the elements in
|
| 585 |
+
`*this` is unspecified. Does not affect the validity of iterators and
|
| 586 |
+
references.
|
| 587 |
+
|
| 588 |
+
*Complexity:* Approximately N log N comparisons, where N is
|
| 589 |
+
`distance(begin(), end())`.
|
| 590 |
+
|
| 591 |
+
*Remarks:* Stable [[algorithm.stable]].
|
| 592 |
+
|
| 593 |
+
``` cpp
|
| 594 |
+
void reverse() noexcept;
|
| 595 |
+
```
|
| 596 |
+
|
| 597 |
+
*Effects:* Reverses the order of the elements in the list. Does not
|
| 598 |
+
affect the validity of iterators and references.
|
| 599 |
+
|
| 600 |
+
*Complexity:* Linear time.
|
| 601 |
+
|
| 602 |
+
#### Erasure <a id="forward.list.erasure">[[forward.list.erasure]]</a>
|
| 603 |
+
|
| 604 |
+
``` cpp
|
| 605 |
+
template<class T, class Allocator, class U>
|
| 606 |
+
typename forward_list<T, Allocator>::size_type
|
| 607 |
+
erase(forward_list<T, Allocator>& c, const U& value);
|
| 608 |
+
```
|
| 609 |
+
|
| 610 |
+
*Effects:* Equivalent to:
|
| 611 |
+
`return erase_if(c, [&](auto& elem) { return elem == value; });`
|
| 612 |
+
|
| 613 |
+
``` cpp
|
| 614 |
+
template<class T, class Allocator, class Predicate>
|
| 615 |
+
typename forward_list<T, Allocator>::size_type
|
| 616 |
+
erase_if(forward_list<T, Allocator>& c, Predicate pred);
|
| 617 |
+
```
|
| 618 |
+
|
| 619 |
+
*Effects:* Equivalent to: `return c.remove_if(pred);`
|
| 620 |
+
|