From Jason Turner

[forwardlist]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp2yl0oiwq/{from.md → to.md} +66 -61
tmp/tmp2yl0oiwq/{from.md → to.md} RENAMED
@@ -10,23 +10,23 @@ access to list elements is not supported. It is intended that
10
  hand-written C-style singly linked list. Features that would conflict
11
  with that goal have been omitted.
12
 
13
  A `forward_list` satisfies all of the requirements of a container
14
  (Table  [[tab:containers.container.requirements]]), except that the
15
- `size()` member function is not provided. A `forward_list` also
16
- satisfies all of the requirements for an allocator-aware container
17
- (Table  [[tab:containers.allocatoraware]]). In addition, a
18
- `forward_list` provides the `assign` member functions (Table 
19
- [[tab:containers.sequence.requirements]]) and several of the optional
20
- container requirements (Table  [[tab:containers.sequence.optional]]).
21
- Descriptions are provided here only for operations on `forward_list`
22
- that are not described in that table or for operations where there is
23
- additional semantic information.
24
 
25
  Modifying any list requires access to the element preceding the first
26
  element of interest, but in a `forward_list` there is no constant-time
27
- way to acess a preceding element. For this reason, ranges that are
28
  modified, such as those supplied to `erase` and `splice`, must be open
29
  at the beginning.
30
 
31
  ``` cpp
32
  namespace std {
@@ -44,12 +44,13 @@ namespace std {
44
  typedef Allocator allocator_type;
45
  typedef typename allocator_traits<Allocator>::pointer pointer;
46
  typedef typename allocator_traits<Allocator>::const_pointer const_pointer;
47
 
48
  // [forwardlist.cons], construct/copy/destroy:
49
- explicit forward_list(const Allocator& = Allocator());
50
- explicit forward_list(size_type n);
 
51
  forward_list(size_type n, const T& value,
52
  const Allocator& = Allocator());
53
  template <class InputIterator>
54
  forward_list(InputIterator first, InputIterator last,
55
  const Allocator& = Allocator());
@@ -161,26 +162,26 @@ namespace std {
161
  ```
162
 
163
  #### `forward_list` constructors, copy, assignment <a id="forwardlist.cons">[[forwardlist.cons]]</a>
164
 
165
  ``` cpp
166
- explicit forward_list(const Allocator& = Allocator());
167
  ```
168
 
169
  *Effects:* Constructs an empty `forward_list` object using the specified
170
  allocator.
171
 
172
  *Complexity:* Constant.
173
 
174
  ``` cpp
175
- explicit forward_list(size_type n);
176
  ```
177
 
178
- *Effects:* Constructs a `forward_list` object with `n` value-initialized
179
- elements.
180
 
181
- *Requires:* `T` shall be `DefaultConstructible`.
182
 
183
  *Complexity:* Linear in `n`.
184
 
185
  ``` cpp
186
  forward_list(size_type n, const T& value, const Allocator& = Allocator());
@@ -201,23 +202,10 @@ template <class InputIterator>
201
  *Effects:* Constructs a `forward_list` object equal to the range
202
  \[`first`, `last`).
203
 
204
  *Complexity:* Linear in `distance(first, last)`.
205
 
206
- ``` cpp
207
- template <class InputIterator>
208
- void assign(InputIterator first, InputIterator last);
209
- ```
210
-
211
- *Effects:* `clear(); insert_after(before_begin(), first, last);`
212
-
213
- ``` cpp
214
- void assign(size_type n, const T& t);
215
- ```
216
-
217
- *Effects:* `clear(); insert_after(before_begin(), n, t);`
218
-
219
  #### `forward_list` iterators <a id="forwardlist.iter">[[forwardlist.iter]]</a>
220
 
221
  ``` cpp
222
  iterator before_begin() noexcept;
223
  const_iterator before_begin() const noexcept;
@@ -316,11 +304,11 @@ iterator insert_after(const_iterator position, initializer_list<T> il);
316
  ```
317
 
318
  *Effects:* `insert_after(p, il.begin(), il.end())`.
319
 
320
  *Returns:* An iterator pointing to the last inserted element or
321
- `position` if `i1` is empty.
322
 
323
  ``` cpp
324
  template <class... Args>
325
  iterator emplace_after(const_iterator position, Args&&... args);
326
  ```
@@ -360,21 +348,31 @@ dereferenceable.
360
 
361
  *Throws:* Nothing.
362
 
363
  ``` cpp
364
  void resize(size_type sz);
 
 
 
 
 
 
 
 
 
 
365
  void resize(size_type sz, const value_type& c);
366
  ```
367
 
368
  *Effects:* If `sz < distance(begin(), end())`, erases the last
369
  `distance(begin(), end()) - sz` elements from the list. Otherwise,
370
- inserts `sz - distance(begin(), end())` elements at the end of the list.
371
- For the first signature the inserted elements are value-initialized, and
372
- for the second signature they are copies of `c`.
 
373
 
374
- *Requires:* `T` shall be `DefaultConstructible` for the first form and
375
- it shall be `CopyInsertable` into `*this` for the second form.
376
 
377
  ``` cpp
378
  void clear() noexcept;
379
  ```
380
 
@@ -388,11 +386,12 @@ void clear() noexcept;
388
  void splice_after(const_iterator position, forward_list& x);
389
  void splice_after(const_iterator position, forward_list&& x);
390
  ```
391
 
392
  *Requires:* `position` is `before_begin()` or is a dereferenceable
393
- iterator in the range \[`begin()`, `end()`). `&x != this`.
 
394
 
395
  *Effects:* Inserts the contents of `x` after `position`, and `x` becomes
396
  empty. Pointers and references to the moved elements of `x` now refer to
397
  those same elements but as members of `*this`. Iterators referring to
398
  the moved elements will continue to refer to their elements, but they
@@ -408,17 +407,18 @@ void splice_after(const_iterator position, forward_list&& x, const_iterator i);
408
  ```
409
 
410
  *Requires:* `position` is `before_begin()` or is a dereferenceable
411
  iterator in the range \[`begin()`, `end()`). The iterator following `i`
412
  is a dereferenceable iterator in `x`.
 
413
 
414
  *Effects:* Inserts the element following `i` into `*this`, following
415
  `position`, and removes it from `x`. The result is unchanged if
416
- `position == i` or `position == ++i`. Pointers and references to `*i`
417
  continue to refer to the same element but as a member of `*this`.
418
- Iterators to `*i` (including `i` itself) continue to refer to the same
419
- element, but now behave as iterators into `*this`, not into `x`.
420
 
421
  *Throws:* Nothing.
422
 
423
  *Complexity:* 𝑂(1)
424
 
@@ -431,11 +431,11 @@ void splice_after(const_iterator position, forward_list&& x,
431
 
432
  *Requires:* `position` is `before_begin()` or is a dereferenceable
433
  iterator in the range \[`begin()`, `end()`). (`first`, `last`) is a
434
  valid range in `x`, and all iterators in the range (`first`, `last`) are
435
  dereferenceable. `position` is not an iterator in the range (`first`,
436
- `last`).
437
 
438
  *Effects:* Inserts elements in the range (`first`, `last`) after
439
  `position` and removes the elements from `x`. Pointers and references to
440
  the moved elements of `x` now refer to those same elements but as
441
  members of `*this`. Iterators referring to the moved elements will
@@ -449,18 +449,18 @@ void remove(const T& value);
449
  template <class Predicate> void remove_if(Predicate pred);
450
  ```
451
 
452
  *Effects:* Erases all the elements in the list referred by a list
453
  iterator `i` for which the following conditions hold: `*i == value` (for
454
- `remove()`), `pred(*i)` is true (for `remove_if()`). This operation
455
- shall be stable: the relative order of the elements that are not removed
456
- is the same as their relative order in the original list. Invalidates
457
- only the iterators and references to the erased elements.
458
 
459
  *Throws:* Nothing unless an exception is thrown by the equality
460
  comparison or the predicate.
461
 
 
 
462
  *Complexity:* Exactly `distance(begin(), end())` applications of the
463
  corresponding predicate.
464
 
465
  ``` cpp
466
  void unique();
@@ -482,28 +482,32 @@ comparison or the predicate.
482
  otherwise no applications of the predicate.
483
 
484
  ``` cpp
485
  void merge(forward_list& x);
486
  void merge(forward_list&& x);
487
- template <class Compare> void merge(forward_list& x, Compare comp)
488
- template <class Compare> void merge(forward_list&& x, Compare comp)
489
  ```
490
 
491
  *Requires:* `comp` defines a strict weak ordering ([[alg.sorting]]),
492
  and `*this` and `x` are both sorted according to this ordering.
 
493
 
494
- *Effects:* Merges `x` into `*this`. This operation shall be stable: for
495
- equivalent elements in the two lists, the elements from `*this` shall
496
- always precede the elements from `x`. `x` is empty after the merge. If
497
- an exception is thrown other than by a comparison there are no effects.
498
- Pointers and references to the moved elements of `x` now refer to those
499
- same elements but as members of `*this`. Iterators referring to the
500
- moved elements will continue to refer to their elements, but they now
501
- behave as iterators into `*this`, not into `x`.
502
 
503
- *Complexity:* At most distance(begin(), end()) + distance(x.begin(),
504
- x.end()) - 1 comparisons.
 
 
 
 
505
 
506
  ``` cpp
507
  void sort();
508
  template <class Compare> void sort(Compare comp);
509
  ```
@@ -511,14 +515,15 @@ template <class Compare> void sort(Compare comp);
511
  *Requires:* `operator<` (for the version with no arguments) or `comp`
512
  (for the version with a comparison argument) defines a strict weak
513
  ordering ([[alg.sorting]]).
514
 
515
  *Effects:* Sorts the list according to the `operator<` or the `comp`
516
- function object. This operation shall be stable: the relative order of
517
- the equivalent elements is preserved. If an exception is thrown the
518
- order of the elements in `*this` is unspecified. Does not affect the
519
- validity of iterators and references.
 
520
 
521
  *Complexity:* Approximately N log N comparisons, where N is
522
  `distance(begin(), end())`.
523
 
524
  ``` cpp
 
10
  hand-written C-style singly linked list. Features that would conflict
11
  with that goal have been omitted.
12
 
13
  A `forward_list` satisfies all of the requirements of a container
14
  (Table  [[tab:containers.container.requirements]]), except that the
15
+ `size()` member function is not provided and `operator==` has linear
16
+ complexity. A `forward_list` also satisfies all of the requirements for
17
+ an allocator-aware container (Table  [[tab:containers.allocatoraware]]).
18
+ In addition, a `forward_list` provides the `assign` member functions
19
+ (Table  [[tab:containers.sequence.requirements]]) and several of the
20
+ optional container requirements (Table 
21
+ [[tab:containers.sequence.optional]]). Descriptions are provided here
22
+ only for operations on `forward_list` that are not described in that
23
+ table or for operations where there is additional semantic information.
24
 
25
  Modifying any list requires access to the element preceding the first
26
  element of interest, but in a `forward_list` there is no constant-time
27
+ way to access a preceding element. For this reason, ranges that are
28
  modified, such as those supplied to `erase` and `splice`, must be open
29
  at the beginning.
30
 
31
  ``` cpp
32
  namespace std {
 
44
  typedef Allocator allocator_type;
45
  typedef typename allocator_traits<Allocator>::pointer pointer;
46
  typedef typename allocator_traits<Allocator>::const_pointer const_pointer;
47
 
48
  // [forwardlist.cons], construct/copy/destroy:
49
+ forward_list() : forward_list(Allocator()) { }
50
+ explicit forward_list(const Allocator&);
51
+ explicit forward_list(size_type n, const Allocator& = Allocator());
52
  forward_list(size_type n, const T& value,
53
  const Allocator& = Allocator());
54
  template <class InputIterator>
55
  forward_list(InputIterator first, InputIterator last,
56
  const Allocator& = Allocator());
 
162
  ```
163
 
164
  #### `forward_list` constructors, copy, assignment <a id="forwardlist.cons">[[forwardlist.cons]]</a>
165
 
166
  ``` cpp
167
+ explicit forward_list(const Allocator&);
168
  ```
169
 
170
  *Effects:* Constructs an empty `forward_list` object using the specified
171
  allocator.
172
 
173
  *Complexity:* Constant.
174
 
175
  ``` cpp
176
+ explicit forward_list(size_type n, const Allocator& = Allocator());
177
  ```
178
 
179
+ *Effects:* Constructs a `forward_list` object with `n` default-inserted
180
+ elements using the specified allocator.
181
 
182
+ *Requires:* `T` shall be `DefaultInsertable` into `*this`.
183
 
184
  *Complexity:* Linear in `n`.
185
 
186
  ``` cpp
187
  forward_list(size_type n, const T& value, const Allocator& = Allocator());
 
202
  *Effects:* Constructs a `forward_list` object equal to the range
203
  \[`first`, `last`).
204
 
205
  *Complexity:* Linear in `distance(first, last)`.
206
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
  #### `forward_list` iterators <a id="forwardlist.iter">[[forwardlist.iter]]</a>
208
 
209
  ``` cpp
210
  iterator before_begin() noexcept;
211
  const_iterator before_begin() const noexcept;
 
304
  ```
305
 
306
  *Effects:* `insert_after(p, il.begin(), il.end())`.
307
 
308
  *Returns:* An iterator pointing to the last inserted element or
309
+ `position` if `il` is empty.
310
 
311
  ``` cpp
312
  template <class... Args>
313
  iterator emplace_after(const_iterator position, Args&&... args);
314
  ```
 
348
 
349
  *Throws:* Nothing.
350
 
351
  ``` cpp
352
  void resize(size_type sz);
353
+ ```
354
+
355
+ *Effects:* If `sz < distance(begin(), end())`, erases the last
356
+ `distance(begin(), end()) - sz` elements from the list. Otherwise,
357
+ inserts `sz - distance(begin(), end())` default-inserted elements at the
358
+ end of the list.
359
+
360
+ *Requires:* `T` shall be `DefaultInsertable` into `*this`.
361
+
362
+ ``` cpp
363
  void resize(size_type sz, const value_type& c);
364
  ```
365
 
366
  *Effects:* If `sz < distance(begin(), end())`, erases the last
367
  `distance(begin(), end()) - sz` elements from the list. Otherwise,
368
+ inserts `sz - distance(begin(), end())` elements at the end of the list
369
+ such that each new element, `e`, is initialized by a method equivalent
370
+ to calling
371
+ `allocator_traits<allocator_type>::construct(get_allocator(), std::addressof(e), c)`.
372
 
373
+ *Requires:* `T` shall be `CopyInsertable` into `*this`.
 
374
 
375
  ``` cpp
376
  void clear() noexcept;
377
  ```
378
 
 
386
  void splice_after(const_iterator position, forward_list& x);
387
  void splice_after(const_iterator position, forward_list&& x);
388
  ```
389
 
390
  *Requires:* `position` is `before_begin()` or is a dereferenceable
391
+ iterator in the range \[`begin()`, `end()`).
392
+ `get_allocator() == x.get_allocator()`. `&x != this`.
393
 
394
  *Effects:* Inserts the contents of `x` after `position`, and `x` becomes
395
  empty. Pointers and references to the moved elements of `x` now refer to
396
  those same elements but as members of `*this`. Iterators referring to
397
  the moved elements will continue to refer to their elements, but they
 
407
  ```
408
 
409
  *Requires:* `position` is `before_begin()` or is a dereferenceable
410
  iterator in the range \[`begin()`, `end()`). The iterator following `i`
411
  is a dereferenceable iterator in `x`.
412
+ `get_allocator() == x.get_allocator()`.
413
 
414
  *Effects:* Inserts the element following `i` into `*this`, following
415
  `position`, and removes it from `x`. The result is unchanged if
416
+ `position == i` or `position == ++i`. Pointers and references to `*++i`
417
  continue to refer to the same element but as a member of `*this`.
418
+ Iterators to `*++i` continue to refer to the same element, but now
419
+ behave as iterators into `*this`, not into `x`.
420
 
421
  *Throws:* Nothing.
422
 
423
  *Complexity:* 𝑂(1)
424
 
 
431
 
432
  *Requires:* `position` is `before_begin()` or is a dereferenceable
433
  iterator in the range \[`begin()`, `end()`). (`first`, `last`) is a
434
  valid range in `x`, and all iterators in the range (`first`, `last`) are
435
  dereferenceable. `position` is not an iterator in the range (`first`,
436
+ `last`). `get_allocator() == x.get_allocator()`.
437
 
438
  *Effects:* Inserts elements in the range (`first`, `last`) after
439
  `position` and removes the elements from `x`. Pointers and references to
440
  the moved elements of `x` now refer to those same elements but as
441
  members of `*this`. Iterators referring to the moved elements will
 
449
  template <class Predicate> void remove_if(Predicate pred);
450
  ```
451
 
452
  *Effects:* Erases all the elements in the list referred by a list
453
  iterator `i` for which the following conditions hold: `*i == value` (for
454
+ `remove()`), `pred(*i)` is true (for `remove_if()`). Invalidates only
455
+ the iterators and references to the erased elements.
 
 
456
 
457
  *Throws:* Nothing unless an exception is thrown by the equality
458
  comparison or the predicate.
459
 
460
+ *Remarks:* Stable ([[algorithm.stable]]).
461
+
462
  *Complexity:* Exactly `distance(begin(), end())` applications of the
463
  corresponding predicate.
464
 
465
  ``` cpp
466
  void unique();
 
482
  otherwise no applications of the predicate.
483
 
484
  ``` cpp
485
  void merge(forward_list& x);
486
  void merge(forward_list&& x);
487
+ template <class Compare> void merge(forward_list& x, Compare comp);
488
+ template <class Compare> void merge(forward_list&& x, Compare comp);
489
  ```
490
 
491
  *Requires:* `comp` defines a strict weak ordering ([[alg.sorting]]),
492
  and `*this` and `x` are both sorted according to this ordering.
493
+ `get_allocator() == x.get_allocator()`.
494
 
495
+ *Effects:* Merges the two sorted ranges `[begin(), end())` and
496
+ `[x.begin(), x.end())`. `x` is empty after the merge. If an exception is
497
+ thrown other than by a comparison there are no effects. Pointers and
498
+ references to the moved elements of `x` now refer to those same elements
499
+ but as members of `*this`. Iterators referring to the moved elements
500
+ will continue to refer to their elements, but they now behave as
501
+ iterators into `*this`, not into `x`.
 
502
 
503
+ *Remarks:* Stable ([[algorithm.stable]]). The behavior is undefined if
504
+ `this->get_allocator() != x.get_allocator()`.
505
+
506
+ *Complexity:* At most
507
+ `distance(begin(), end()) + distance(x.begin(), x.end()) - 1`
508
+ comparisons.
509
 
510
  ``` cpp
511
  void sort();
512
  template <class Compare> void sort(Compare comp);
513
  ```
 
515
  *Requires:* `operator<` (for the version with no arguments) or `comp`
516
  (for the version with a comparison argument) defines a strict weak
517
  ordering ([[alg.sorting]]).
518
 
519
  *Effects:* Sorts the list according to the `operator<` or the `comp`
520
+ function object. If an exception is thrown the order of the elements in
521
+ `*this` is unspecified. Does not affect the validity of iterators and
522
+ references.
523
+
524
+ *Remarks:* Stable ([[algorithm.stable]]).
525
 
526
  *Complexity:* Approximately N log N comparisons, where N is
527
  `distance(begin(), end())`.
528
 
529
  ``` cpp