From Jason Turner

[iterators]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp2_fnllq6/{from.md → to.md} +181 -155
tmp/tmp2_fnllq6/{from.md → to.md} RENAMED
@@ -75,10 +75,11 @@ namespace std {
75
  // [iterator.concepts], iterator concepts
76
  // [iterator.concept.readable], concept indirectly_readable
77
  template<class In>
78
  concept indirectly_readable = see below; // freestanding
79
 
 
80
  template<indirectly_readable T>
81
  using indirect-value-t = see below; // exposition only
82
 
83
  template<indirectly_readable T>
84
  using iter_common_reference_t = // freestanding
@@ -159,14 +160,15 @@ namespace std {
159
  requires (indirectly_readable<Is> && ...) && invocable<F, iter_reference_t<Is>...>
160
  using indirect_result_t = invoke_result_t<F, iter_reference_t<Is>...>; // freestanding
161
 
162
  // [projected], projected
163
  template<indirectly_readable I, indirectly_regular_unary_invocable<I> Proj>
164
- struct projected; // freestanding
165
 
166
- template<weakly_incrementable I, class Proj>
167
- struct incrementable_traits<projected<I, Proj>>; // freestanding
 
168
 
169
  // [alg.req], common algorithm requirements
170
  // [alg.req.ind.move], concept indirectly_movable
171
  template<class In, class Out>
172
  concept indirectly_movable = see below; // freestanding
@@ -311,11 +313,11 @@ namespace std {
311
  template<class Iterator>
312
  constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // freestanding
313
 
314
  template<class Iterator1, class Iterator2>
315
  requires (!sized_sentinel_for<Iterator1, Iterator2>)
316
- constexpr bool disable_sized_sentinel_for<reverse_iterator<Iterator1>, // freestanding
317
  reverse_iterator<Iterator2>> = true;
318
 
319
  // [insert.iterators], insert iterators
320
  template<class Container> class back_insert_iterator; // freestanding
321
  template<class Container>
@@ -401,11 +403,11 @@ namespace std {
401
  template<class Iterator>
402
  constexpr move_iterator<Iterator> make_move_iterator(Iterator i); // freestanding
403
 
404
  template<class Iterator1, class Iterator2>
405
  requires (!sized_sentinel_for<Iterator1, Iterator2>)
406
- constexpr bool disable_sized_sentinel_for<move_iterator<Iterator1>, // freestanding
407
  move_iterator<Iterator2>> = true;
408
 
409
  template<semiregular S> class move_sentinel; // freestanding
410
 
411
  // [iterators.common], common iterators
@@ -489,15 +491,15 @@ namespace std {
489
  ssize(const C& c)
490
  -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // freestanding
491
  template<class T, ptrdiff_t N> constexpr ptrdiff_t
492
  ssize(const T (&array)[N]) noexcept; // freestanding
493
 
494
- template<class C> [[nodiscard]] constexpr auto
495
  empty(const C& c) -> decltype(c.empty()); // freestanding
496
- template<class T, size_t N> [[nodiscard]] constexpr bool
497
  empty(const T (&array)[N]) noexcept; // freestanding
498
- template<class E> [[nodiscard]] constexpr bool
499
  empty(initializer_list<E> il) noexcept; // freestanding
500
 
501
  template<class C> constexpr auto data(C& c) -> decltype(c.data()); // freestanding
502
  template<class C> constexpr auto data(const C& c) -> decltype(c.data()); // freestanding
503
  template<class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // freestanding
@@ -505,25 +507,25 @@ namespace std {
505
  }
506
  ```
507
 
508
  ## Iterator requirements <a id="iterator.requirements">[[iterator.requirements]]</a>
509
 
510
- ### In general <a id="iterator.requirements.general">[[iterator.requirements.general]]</a>
511
 
512
  Iterators are a generalization of pointers that allow a C++ program to
513
  work with different data structures (for example, containers and ranges)
514
  in a uniform manner. To be able to construct template algorithms that
515
  work correctly and efficiently on different types of data structures,
516
  the library formalizes not just the interfaces but also the semantics
517
  and complexity assumptions of iterators. An input iterator `i` supports
518
  the expression `*i`, resulting in a value of some object type `T`,
519
  called the *value type* of the iterator. An output iterator `i` has a
520
- non-empty set of types that are `indirectly_writable` to the iterator;
521
- for each such type `T`, the expression `*i = o` is valid where `o` is a
522
- value of type `T`. For every iterator type `X`, there is a corresponding
523
- signed integer-like type [[iterator.concept.winc]] called the
524
- *difference type* of the iterator.
525
 
526
  Since iterators are an abstraction of pointers, their semantics are a
527
  generalization of most of the semantics of pointers in C++. This ensures
528
  that every function template that takes iterators works as well with
529
  regular pointers. This document defines six categories of iterators,
@@ -620,25 +622,41 @@ A counted range `i`+\[0, `n`) is *valid* if and only if `n == 0`; or `n`
620
  is positive, `i` is dereferenceable, and `++i`+\[0, `–n`) is valid.
621
 
622
  The result of the application of library functions to invalid ranges is
623
  undefined.
624
 
 
 
 
 
 
 
 
 
 
 
 
 
 
625
  All the categories of iterators require only those functions that are
626
  realizable for a given category in constant time (amortized). Therefore,
627
  requirement tables and concept definitions for the iterators do not
628
  specify complexity.
629
 
630
- Destruction of a non-forward iterator may invalidate pointers and
631
- references previously obtained from that iterator.
 
 
632
 
633
  An *invalid iterator* is an iterator that may be singular.[^2]
634
 
635
- Iterators are called *constexpr iterators* if all operations provided to
636
- meet iterator category requirements are constexpr functions.
637
 
638
- [*Note 3*: For example, the types “pointer to `int`” and
639
- `reverse_iterator<int*>` are constexpr iterators. — *end note*]
 
640
 
641
  ### Associated types <a id="iterator.assoc.types">[[iterator.assoc.types]]</a>
642
 
643
  #### Incrementable traits <a id="incrementable.traits">[[incrementable.traits]]</a>
644
 
@@ -669,11 +687,11 @@ namespace std {
669
  : incrementable_traits<I> { };
670
 
671
  template<class T>
672
  requires requires { typename T::difference_type; }
673
  struct incrementable_traits<T> {
674
- using difference_type = typename T::difference_type;
675
  };
676
 
677
  template<class T>
678
  requires (!requires { typename T::difference_type; } &&
679
  requires(const T& a, const T& b) { { a - b } -> integral; })
@@ -874,27 +892,27 @@ The members of a specialization `iterator_traits<I>` generated from the
874
 
875
  - If `I` has valid [[temp.deduct]] member types `difference_type`,
876
  `value_type`, `reference`, and `iterator_category`, then
877
  `iterator_traits<I>` has the following publicly accessible members:
878
  ``` cpp
879
- using iterator_category = typename I::iterator_category;
880
- using value_type = typename I::value_type;
881
- using difference_type = typename I::difference_type;
882
  using pointer = see below;
883
- using reference = typename I::reference;
884
  ```
885
 
886
  If the *qualified-id* `I::pointer` is valid and denotes a type, then
887
  `iterator_traits<I>::pointer` names that type; otherwise, it names
888
  `void`.
889
  - Otherwise, if `I` satisfies the exposition-only concept
890
  `cpp17-input-iterator`, `iterator_traits<I>` has the following
891
  publicly accessible members:
892
  ``` cpp
893
  using iterator_category = see below;
894
- using value_type = typename indirectly_readable_traits<I>::value_type;
895
- using difference_type = typename incrementable_traits<I>::difference_type;
896
  using pointer = see below;
897
  using reference = see below;
898
  ```
899
 
900
  - If the *qualified-id* `I::pointer` is valid and denotes a type,
@@ -964,16 +982,14 @@ To implement a generic `reverse` function, a C++ program can do the
964
  following:
965
 
966
  ``` cpp
967
  template<class BI>
968
  void reverse(BI first, BI last) {
969
- typename iterator_traits<BI>::difference_type n =
970
- distance(first, last);
971
  --n;
972
  while (n > 0) {
973
- typename iterator_traits<BI>::value_type
974
- tmp = *first;
975
  *first++ = *--last;
976
  *last = tmp;
977
  n -= 2;
978
  }
979
  }
@@ -1008,11 +1024,11 @@ ill-formed, no diagnostic required.
1008
 
1009
  The name `ranges::iter_swap` denotes a customization point object
1010
  [[customization.point.object]] that exchanges the values
1011
  [[concept.swappable]] denoted by its arguments.
1012
 
1013
- Let *`iter-exchange-move`* be the exposition-only function:
1014
 
1015
  ``` cpp
1016
  template<class X, class Y>
1017
  constexpr iter_value_t<X> iter-exchange-move(X&& x, Y&& y)
1018
  noexcept(noexcept(iter_value_t<X>(iter_move(x))) &&
@@ -1108,11 +1124,11 @@ Types that are indirectly readable by applying `operator*` model the
1108
  `indirectly_readable` concept, including pointers, smart pointers, and
1109
  iterators.
1110
 
1111
  ``` cpp
1112
  template<class In>
1113
- concept indirectly-readable-impl =
1114
  requires(const In in) {
1115
  typename iter_value_t<In>;
1116
  typename iter_reference_t<In>;
1117
  typename iter_rvalue_reference_t<In>;
1118
  { *in } -> same_as<iter_reference_t<In>>;
@@ -1150,11 +1166,11 @@ template<class Out, class T>
1150
  };
1151
  ```
1152
 
1153
  Let `E` be an expression such that `decltype((E))` is `T`, and let `o`
1154
  be a dereferenceable object of type `Out`. `Out` and `T` model
1155
- `indirectly_writable<Out, T>` only if
1156
 
1157
  - If `Out` and `T` model
1158
  `indirectly_readable<Out> && same_as<iter_value_t<Out>, decay_t<T>>`,
1159
  then `*o` after any above assignment is equal to the value of `E`
1160
  before the assignment.
@@ -1303,19 +1319,19 @@ a signed-integer-like type.
1303
  type. `is-signed-integer-like<I>` is `true` if and only if `I` is a
1304
  signed-integer-like type.
1305
 
1306
  Let `i` be an object of type `I`. When `i` is in the domain of both pre-
1307
  and post-increment, `i` is said to be *incrementable*. `I` models
1308
- `weakly_incrementable<I>` only if
1309
 
1310
  - The expressions `++i` and `i++` have the same domain.
1311
  - If `i` is incrementable, then both `++i` and `i++` advance `i` to the
1312
  next element.
1313
  - If `i` is incrementable, then `addressof(++i)` is equal to
1314
  `addressof(i)`.
1315
 
1316
- *Recommended practice:* The implementaton of an algorithm on a weakly
1317
  incrementable type should never attempt to pass through the same
1318
  incrementable value twice; such an algorithm should be a single-pass
1319
  algorithm.
1320
 
1321
  [*Note 3*: For `weakly_incrementable` types, `a` equals `b` does not
@@ -1329,12 +1345,13 @@ be used with istreams as the source of the input data through the
1329
  The `incrementable` concept specifies requirements on types that can be
1330
  incremented with the pre- and post-increment operators. The increment
1331
  operations are required to be equality-preserving, and the type is
1332
  required to be `equality_comparable`.
1333
 
1334
- [*Note 1*: This supersedes the annotations on the increment expressions
1335
- in the definition of `weakly_incrementable`. *end note*]
 
1336
 
1337
  ``` cpp
1338
  template<class I>
1339
  concept incrementable =
1340
  regular<I> &&
@@ -1343,11 +1360,11 @@ template<class I>
1343
  { i++ } -> same_as<I>;
1344
  };
1345
  ```
1346
 
1347
  Let `a` and `b` be incrementable objects of type `I`. `I` models
1348
- `incrementable` only if
1349
 
1350
  - If `bool(a == b)` then `bool(a++ == b)`.
1351
  - If `bool(a == b)` then `bool(((void)a++, a) == ++b)`.
1352
 
1353
  [*Note 2*: The requirement that `a` equals `b` implies `++a` equals
@@ -1392,11 +1409,11 @@ template<class S, class I>
1392
  input_or_output_iterator<I> &&
1393
  weakly-equality-comparable-with<S, I>; // see [concept.equalitycomparable]
1394
  ```
1395
 
1396
  Let `s` and `i` be values of type `S` and `I` such that \[`i`, `s`)
1397
- denotes a range. Types `S` and `I` model `sentinel_for<S, I>` only if
1398
 
1399
  - `i == s` is well-defined.
1400
  - If `bool(i != s)` then `i` is dereferenceable and \[`++i`, `s`)
1401
  denotes a range.
1402
  - `assignable_from<I&, S>` is either modeled or not satisfied.
@@ -1426,11 +1443,11 @@ template<class S, class I>
1426
  ```
1427
 
1428
  Let `i` be an iterator of type `I`, and `s` a sentinel of type `S` such
1429
  that \[`i`, `s`) denotes a range. Let N be the smallest number of
1430
  applications of `++i` necessary to make `bool(i == s)` be `true`. `S`
1431
- and `I` model `sized_sentinel_for<S, I>` only if
1432
 
1433
  - If N is representable by `iter_difference_t<I>`, then `s - i` is
1434
  well-defined and equals N.
1435
  - If -N is representable by `iter_difference_t<I>`, then `i - s` is
1436
  well-defined and equals -N.
@@ -1534,11 +1551,11 @@ end of the same empty sequence. — *end note*]
1534
  Pointers and references obtained from a forward iterator into a range
1535
  \[`i`, `s`) shall remain valid while \[`i`, `s`) continues to denote a
1536
  range.
1537
 
1538
  Two dereferenceable iterators `a` and `b` of type `X` offer the
1539
- *multi-pass guarantee* if:
1540
 
1541
  - `a == b` implies `++a == ++b` and
1542
  - the expression `((void)[](X x){++x;}(a), *a)` is equivalent to the
1543
  expression `*a`.
1544
 
@@ -1605,11 +1622,11 @@ template<class I>
1605
  ```
1606
 
1607
  Let `a` and `b` be valid iterators of type `I` such that `b` is
1608
  reachable from `a` after `n` applications of `++a`, let `D` be
1609
  `iter_difference_t<I>`, and let `n` denote a value of type `D`. `I`
1610
- models `random_access_iterator` only if
1611
 
1612
  - `(a += n)` is equal to `b`.
1613
  - `addressof(a += n)` is equal to `addressof(a)`.
1614
  - `(a + n)` is equal to `(a += n)`.
1615
  - For any two positive values `x` and `y` of type `D`, if
@@ -1649,10 +1666,11 @@ non-dereferenceable iterator of type `I` such that `b` is reachable from
1649
  if
1650
 
1651
  - `to_address(a) == addressof(*a)`,
1652
  - `to_address(b) == to_address(a) + D(b - a)`,
1653
  - `to_address(c) == to_address(a) + D(c - a)`,
 
1654
  - `ranges::iter_move(a)` has the same type, value category, and effects
1655
  as `std::move(*a)`, and
1656
  - if `ranges::iter_swap(a, b)` is well-formed, it has effects equivalent
1657
  to `ranges::swap(*a, *b)`.
1658
 
@@ -1679,11 +1697,11 @@ set of requirements specifies operations for dereferencing and
1679
  incrementing an iterator. Most algorithms will require additional
1680
  operations to read [[input.iterators]] or write [[output.iterators]]
1681
  values, or to provide a richer set of iterator movements
1682
  [[forward.iterators]], [[bidirectional.iterators]], [[random.access.iterators]].
1683
 
1684
- A type `X` meets the requirements if:
1685
 
1686
  - `X` meets the *Cpp17CopyConstructible*, *Cpp17CopyAssignable*,
1687
  *Cpp17Swappable*, and *Cpp17Destructible* requirements
1688
  [[utility.arg.requirements]], [[swappable.requirements]], and
1689
  - `iterator_traits<X>::difference_type` is a signed integer type or
@@ -1738,12 +1756,12 @@ the assignment statement. Assignment through the same value of the
1738
  iterator happens only once. Equality and inequality are not necessarily
1739
  defined. — *end note*]
1740
 
1741
  #### Forward iterators <a id="forward.iterators">[[forward.iterators]]</a>
1742
 
1743
- A class or pointer type `X` meets the requirements of a forward iterator
1744
- if
1745
 
1746
  - `X` meets the *Cpp17InputIterator* requirements [[input.iterators]],
1747
  - `X` meets the *Cpp17DefaultConstructible* requirements
1748
  [[utility.arg.requirements]],
1749
  - if `X` is a mutable iterator, `reference` is a reference to `T`; if
@@ -1759,11 +1777,11 @@ the same type.
1759
 
1760
  [*Note 1*: Value-initialized iterators behave as if they refer past the
1761
  end of the same empty sequence. — *end note*]
1762
 
1763
  Two dereferenceable iterators `a` and `b` of type `X` offer the
1764
- *multi-pass guarantee* if:
1765
 
1766
  - `a == b` implies `++a == ++b` and
1767
  - `X` is a pointer type or the expression `(void)++X(a), *a` is
1768
  equivalent to the expression `*a`.
1769
 
@@ -1824,86 +1842,82 @@ namespace std {
1824
  concept indirectly_unary_invocable =
1825
  indirectly_readable<I> &&
1826
  copy_constructible<F> &&
1827
  invocable<F&, indirect-value-t<I>> &&
1828
  invocable<F&, iter_reference_t<I>> &&
1829
- invocable<F&, iter_common_reference_t<I>> &&
1830
  common_reference_with<
1831
  invoke_result_t<F&, indirect-value-t<I>>,
1832
  invoke_result_t<F&, iter_reference_t<I>>>;
1833
 
1834
  template<class F, class I>
1835
  concept indirectly_regular_unary_invocable =
1836
  indirectly_readable<I> &&
1837
  copy_constructible<F> &&
1838
  regular_invocable<F&, indirect-value-t<I>> &&
1839
  regular_invocable<F&, iter_reference_t<I>> &&
1840
- regular_invocable<F&, iter_common_reference_t<I>> &&
1841
  common_reference_with<
1842
  invoke_result_t<F&, indirect-value-t<I>>,
1843
  invoke_result_t<F&, iter_reference_t<I>>>;
1844
 
1845
  template<class F, class I>
1846
  concept indirect_unary_predicate =
1847
  indirectly_readable<I> &&
1848
  copy_constructible<F> &&
1849
  predicate<F&, indirect-value-t<I>> &&
1850
- predicate<F&, iter_reference_t<I>> &&
1851
- predicate<F&, iter_common_reference_t<I>>;
1852
 
1853
  template<class F, class I1, class I2>
1854
  concept indirect_binary_predicate =
1855
  indirectly_readable<I1> && indirectly_readable<I2> &&
1856
  copy_constructible<F> &&
1857
  predicate<F&, indirect-value-t<I1>, indirect-value-t<I2>> &&
1858
  predicate<F&, indirect-value-t<I1>, iter_reference_t<I2>> &&
1859
  predicate<F&, iter_reference_t<I1>, indirect-value-t<I2>> &&
1860
- predicate<F&, iter_reference_t<I1>, iter_reference_t<I2>> &&
1861
- predicate<F&, iter_common_reference_t<I1>, iter_common_reference_t<I2>>;
1862
 
1863
  template<class F, class I1, class I2 = I1>
1864
  concept indirect_equivalence_relation =
1865
  indirectly_readable<I1> && indirectly_readable<I2> &&
1866
  copy_constructible<F> &&
1867
  equivalence_relation<F&, indirect-value-t<I1>, indirect-value-t<I2>> &&
1868
  equivalence_relation<F&, indirect-value-t<I1>, iter_reference_t<I2>> &&
1869
  equivalence_relation<F&, iter_reference_t<I1>, indirect-value-t<I2>> &&
1870
- equivalence_relation<F&, iter_reference_t<I1>, iter_reference_t<I2>> &&
1871
- equivalence_relation<F&, iter_common_reference_t<I1>, iter_common_reference_t<I2>>;
1872
 
1873
  template<class F, class I1, class I2 = I1>
1874
  concept indirect_strict_weak_order =
1875
  indirectly_readable<I1> && indirectly_readable<I2> &&
1876
  copy_constructible<F> &&
1877
  strict_weak_order<F&, indirect-value-t<I1>, indirect-value-t<I2>> &&
1878
  strict_weak_order<F&, indirect-value-t<I1>, iter_reference_t<I2>> &&
1879
  strict_weak_order<F&, iter_reference_t<I1>, indirect-value-t<I2>> &&
1880
- strict_weak_order<F&, iter_reference_t<I1>, iter_reference_t<I2>> &&
1881
- strict_weak_order<F&, iter_common_reference_t<I1>, iter_common_reference_t<I2>>;
1882
  }
1883
  ```
1884
 
1885
- #### Class template `projected` <a id="projected">[[projected]]</a>
1886
 
1887
- Class template `projected` is used to constrain algorithms that accept
1888
  callable objects and projections [[defns.projection]]. It combines an
1889
  `indirectly_readable` type `I` and a callable object type `Proj` into a
1890
  new `indirectly_readable` type whose `reference` type is the result of
1891
  applying `Proj` to the `iter_reference_t` of `I`.
1892
 
1893
  ``` cpp
1894
  namespace std {
1895
- template<indirectly_readable I, indirectly_regular_unary_invocable<I> Proj>
1896
- struct projected {
 
1897
  using value_type = remove_cvref_t<indirect_result_t<Proj&, I>>;
 
 
1898
  indirect_result_t<Proj&, I> operator*() const; // not defined
1899
  };
1900
-
1901
- template<weakly_incrementable I, class Proj>
1902
- struct incrementable_traits<projected<I, Proj>> {
1903
- using difference_type = iter_difference_t<I>;
1904
  };
 
 
 
1905
  }
1906
  ```
1907
 
1908
  ### Common algorithm requirements <a id="alg.req">[[alg.req]]</a>
1909
 
@@ -2222,38 +2236,12 @@ possible for a concrete iterator type.
2222
  `random_access_iterator` forward `n` steps in constant time. For an
2223
  iterator type that does not model `random_access_iterator`,
2224
  `ranges::advance` instead performs `n` individual increments with the
2225
  `++` operator. — *end example*]
2226
 
2227
- The function templates defined in [[range.iter.ops]] are not found by
2228
- argument-dependent name lookup [[basic.lookup.argdep]]. When found by
2229
- unqualified [[basic.lookup.unqual]] name lookup for the
2230
- *postfix-expression* in a function call [[expr.call]], they inhibit
2231
- argument-dependent name lookup.
2232
-
2233
- [*Example 2*:
2234
-
2235
- ``` cpp
2236
- void foo() {
2237
- using namespace std::ranges;
2238
- std::vector<int> vec{1,2,3};
2239
- distance(begin(vec), end(vec)); // #1
2240
- }
2241
- ```
2242
-
2243
- The function call expression at `#1` invokes `std::ranges::distance`,
2244
- not `std::distance`, despite that (a) the iterator type returned from
2245
- `begin(vec)` and `end(vec)` may be associated with namespace `std` and
2246
- (b) `std::distance` is more specialized [[temp.func.order]] than
2247
- `std::ranges::distance` since the former requires its first two
2248
- parameters to have the same type.
2249
-
2250
- — *end example*]
2251
-
2252
- The number and order of deducible template parameters for the function
2253
- templates defined in [[range.iter.ops]] is unspecified, except where
2254
- explicitly stated otherwise.
2255
 
2256
  #### `ranges::advance` <a id="range.iter.op.advance">[[range.iter.op.advance]]</a>
2257
 
2258
  ``` cpp
2259
  template<input_or_output_iterator I>
@@ -2327,11 +2315,17 @@ number of increments.
2327
  template<class I, sized_sentinel_for<decay_t<I>> S>
2328
  constexpr iter_difference_t<decay_t<I>> ranges::distance(I&& first, S last);
2329
  ```
2330
 
2331
  *Effects:* Equivalent to:
2332
- `return last - static_cast<const decay_t<I>&>(first);`
 
 
 
 
 
 
2333
 
2334
  ``` cpp
2335
  template<range R>
2336
  constexpr range_difference_t<R> ranges::distance(R&& r);
2337
  ```
@@ -2421,11 +2415,11 @@ namespace std {
2421
  using iterator_type = Iterator;
2422
  using iterator_concept = see below;
2423
  using iterator_category = see below;
2424
  using value_type = iter_value_t<Iterator>;
2425
  using difference_type = iter_difference_t<Iterator>;
2426
- using pointer = typename iterator_traits<Iterator>::pointer;
2427
  using reference = iter_reference_t<Iterator>;
2428
 
2429
  constexpr reverse_iterator();
2430
  constexpr explicit reverse_iterator(Iterator x);
2431
  template<class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
@@ -2498,14 +2492,11 @@ are instantiated [[temp.inst]].
2498
 
2499
  ``` cpp
2500
  constexpr reverse_iterator();
2501
  ```
2502
 
2503
- *Effects:* Value-initializes `current`. Iterator operations applied to
2504
- the resulting iterator have defined behavior if and only if the
2505
- corresponding operations are defined on a value-initialized iterator of
2506
- type `Iterator`.
2507
 
2508
  ``` cpp
2509
  constexpr explicit reverse_iterator(Iterator x);
2510
  ```
2511
 
@@ -2831,10 +2822,12 @@ the iterator points to in a container. `back_inserter`,
2831
  `front_inserter`, and `inserter` are three functions making the insert
2832
  iterators out of a container.
2833
 
2834
  #### Class template `back_insert_iterator` <a id="back.insert.iterator">[[back.insert.iterator]]</a>
2835
 
 
 
2836
  ``` cpp
2837
  namespace std {
2838
  template<class Container>
2839
  class back_insert_iterator {
2840
  protected:
@@ -2905,10 +2898,12 @@ template<class Container>
2905
 
2906
  *Returns:* `back_insert_iterator<Container>(x)`.
2907
 
2908
  #### Class template `front_insert_iterator` <a id="front.insert.iterator">[[front.insert.iterator]]</a>
2909
 
 
 
2910
  ``` cpp
2911
  namespace std {
2912
  template<class Container>
2913
  class front_insert_iterator {
2914
  protected:
@@ -2979,10 +2974,12 @@ template<class Container>
2979
 
2980
  *Returns:* `front_insert_iterator<Container>(x)`.
2981
 
2982
  #### Class template `insert_iterator` <a id="insert.iterator">[[insert.iterator]]</a>
2983
 
 
 
2984
  ``` cpp
2985
  namespace std {
2986
  template<class Container>
2987
  class insert_iterator {
2988
  protected:
@@ -3161,10 +3158,17 @@ namespace std {
3161
  requires random_access_iterator<Iterator>;
3162
 
3163
  template<sentinel_for<Iterator> S>
3164
  constexpr bool operator==(const S& s) const;
3165
 
 
 
 
 
 
 
 
3166
  constexpr bool operator<(const basic_const_iterator& y) const
3167
  requires random_access_iterator<Iterator>;
3168
  constexpr bool operator>(const basic_const_iterator& y) const
3169
  requires random_access_iterator<Iterator>;
3170
  constexpr bool operator<=(const basic_const_iterator& y) const
@@ -3382,10 +3386,26 @@ template<sentinel_for<Iterator> S>
3382
  constexpr bool operator==(const S& s) const;
3383
  ```
3384
 
3385
  *Effects:* Equivalent to: `return `*`current_`*` == s;`
3386
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3387
  ``` cpp
3388
  constexpr bool operator<(const basic_const_iterator& y) const
3389
  requires random_access_iterator<Iterator>;
3390
  constexpr bool operator>(const basic_const_iterator& y) const
3391
  requires random_access_iterator<Iterator>;
@@ -3440,11 +3460,11 @@ template<not-a-const-iterator I>
3440
  requires random_access_iterator<Iterator> && totally_ordered_with<Iterator, I>;
3441
  ```
3442
 
3443
  Let *`op`* be the operator.
3444
 
3445
- *Returns:* Equivalent to: `return x `*`op`*` y.`*`current_`*`;`
3446
 
3447
  ``` cpp
3448
  friend constexpr basic_const_iterator operator+(const basic_const_iterator& i, difference_type n)
3449
  requires random_access_iterator<Iterator>;
3450
  friend constexpr basic_const_iterator operator+(difference_type n, const basic_const_iterator& i)
@@ -3994,11 +4014,11 @@ namespace std {
3994
  template<sized_sentinel_for<I> I2, sized_sentinel_for<I> S2>
3995
  requires sized_sentinel_for<S, I2>
3996
  friend constexpr iter_difference_t<I2> operator-(
3997
  const common_iterator& x, const common_iterator<I2, S2>& y);
3998
 
3999
- friend constexpr iter_rvalue_reference_t<I> iter_move(const common_iterator& i)
4000
  noexcept(noexcept(ranges::iter_move(declval<const I&>())))
4001
  requires input_iterator<I>;
4002
  template<indirectly_swappable<I> I2, class S2>
4003
  friend constexpr void iter_swap(const common_iterator& x, const common_iterator<I2, S2>& y)
4004
  noexcept(noexcept(ranges::iter_swap(declval<const I&>(), declval<const I2&>())));
@@ -4013,30 +4033,34 @@ namespace std {
4013
  };
4014
 
4015
  template<input_iterator I, class S>
4016
  struct iterator_traits<common_iterator<I, S>> {
4017
  using iterator_concept = see below;
4018
- using iterator_category = see below;
4019
  using value_type = iter_value_t<I>;
4020
  using difference_type = iter_difference_t<I>;
4021
  using pointer = see below;
4022
  using reference = iter_reference_t<I>;
4023
  };
4024
  }
4025
  ```
4026
 
4027
  #### Associated types <a id="common.iter.types">[[common.iter.types]]</a>
4028
 
4029
- The nested *typedef-name*s of the specialization of `iterator_traits`
4030
- for `common_iterator<I, S>` are defined as follows.
 
 
 
 
 
 
 
 
4031
 
4032
  - `iterator_concept` denotes `forward_iterator_tag` if `I` models
4033
  `forward_iterator`; otherwise it denotes `input_iterator_tag`.
4034
- - `iterator_category` denotes `forward_iterator_tag` if the
4035
- *qualified-id* `iterator_traits<I>::iterator_category` is valid and
4036
- denotes a type that models `derived_from<forward_iterator_tag>`;
4037
- otherwise it denotes `input_iterator_tag`.
4038
  - Let `a` denote an lvalue of type `const common_iterator<I, S>`. If the
4039
  expression `a.operator->()` is well-formed, then `pointer` denotes
4040
  `decltype(a.operator->())`. Otherwise, `pointer` denotes `void`.
4041
 
4042
  #### Constructors and conversions <a id="common.iter.const">[[common.iter.const]]</a>
@@ -4059,11 +4083,11 @@ constexpr common_iterator(S s);
4059
  template<class I2, class S2>
4060
  requires convertible_to<const I2&, I> && convertible_to<const S2&, S>
4061
  constexpr common_iterator(const common_iterator<I2, S2>& x);
4062
  ```
4063
 
4064
- *Preconditions:* `x.v_.valueless_by_exception()` is `false`.
4065
 
4066
  *Effects:* Initializes `v_` as if by
4067
  `v_{in_place_index<`i`>, get<`i`>(x.v_)}`, where i is `x.v_.index()`.
4068
 
4069
  ``` cpp
@@ -4071,30 +4095,30 @@ template<class I2, class S2>
4071
  requires convertible_to<const I2&, I> && convertible_to<const S2&, S> &&
4072
  assignable_from<I&, const I2&> && assignable_from<S&, const S2&>
4073
  constexpr common_iterator& operator=(const common_iterator<I2, S2>& x);
4074
  ```
4075
 
4076
- *Preconditions:* `x.v_.valueless_by_exception()` is `false`.
4077
 
4078
  *Effects:* Equivalent to:
4079
 
4080
  - If `v_.index() == x.v_.index()`, then `get<`i`>(v_) = get<`i`>(x.v_)`.
4081
  - Otherwise, `v_.emplace<`i`>(get<`i`>(x.v_))`.
4082
 
4083
  where i is `x.v_.index()`.
4084
 
4085
- *Returns:* `*this`
4086
 
4087
  #### Accessors <a id="common.iter.access">[[common.iter.access]]</a>
4088
 
4089
  ``` cpp
4090
  constexpr decltype(auto) operator*();
4091
  constexpr decltype(auto) operator*() const
4092
  requires dereferenceable<const I>;
4093
  ```
4094
 
4095
- *Preconditions:* `holds_alternative<I>(v_)` is `true`.
4096
 
4097
  *Effects:* Equivalent to: `return *get<I>(v_);`
4098
 
4099
  ``` cpp
4100
  constexpr auto operator->() const
@@ -4108,11 +4132,11 @@ indirectly_readable<const I> &&
4108
  (requires(const I& i) { i.operator->(); } ||
4109
  is_reference_v<iter_reference_t<I>> ||
4110
  constructible_from<iter_value_t<I>, iter_reference_t<I>>)
4111
  ```
4112
 
4113
- *Preconditions:* `holds_alternative<I>(v_)` is `true`.
4114
 
4115
  *Effects:*
4116
 
4117
  - If `I` is a pointer type or if the expression
4118
  `get<I>(v_).operator->()` is well-formed, equivalent to:
@@ -4141,21 +4165,21 @@ indirectly_readable<const I> &&
4141
 
4142
  ``` cpp
4143
  constexpr common_iterator& operator++();
4144
  ```
4145
 
4146
- *Preconditions:* `holds_alternative<I>(v_)` is `true`.
4147
 
4148
  *Effects:* Equivalent to `++get<I>(v_)`.
4149
 
4150
  *Returns:* `*this`.
4151
 
4152
  ``` cpp
4153
  constexpr decltype(auto) operator++(int);
4154
  ```
4155
 
4156
- *Preconditions:* `holds_alternative<I>(v_)` is `true`.
4157
 
4158
  *Effects:* If `I` models `forward_iterator`, equivalent to:
4159
 
4160
  ``` cpp
4161
  common_iterator tmp = *this;
@@ -4206,12 +4230,12 @@ template<class I2, sentinel_for<I> S2>
4206
  requires sentinel_for<S, I2>
4207
  friend constexpr bool operator==(
4208
  const common_iterator& x, const common_iterator<I2, S2>& y);
4209
  ```
4210
 
4211
- *Preconditions:* `x.v_.valueless_by_exception()` and
4212
- `y.v_.valueless_by_exception()` are each `false`.
4213
 
4214
  *Returns:* `true` if i` == `j, and otherwise
4215
  `get<`i`>(x.v_) == get<`j`>(y.v_)`, where i is `x.v_.index()` and j is
4216
  `y.v_.index()`.
4217
 
@@ -4220,12 +4244,12 @@ template<class I2, sentinel_for<I> S2>
4220
  requires sentinel_for<S, I2> && equality_comparable_with<I, I2>
4221
  friend constexpr bool operator==(
4222
  const common_iterator& x, const common_iterator<I2, S2>& y);
4223
  ```
4224
 
4225
- *Preconditions:* `x.v_.valueless_by_exception()` and
4226
- `y.v_.valueless_by_exception()` are each `false`.
4227
 
4228
  *Returns:* `true` if i and j are each `1`, and otherwise
4229
  `get<`i`>(x.v_) == get<`j`>(y.v_)`, where i is `x.v_.index()` and j is
4230
  `y.v_.index()`.
4231
 
@@ -4234,37 +4258,37 @@ template<sized_sentinel_for<I> I2, sized_sentinel_for<I> S2>
4234
  requires sized_sentinel_for<S, I2>
4235
  friend constexpr iter_difference_t<I2> operator-(
4236
  const common_iterator& x, const common_iterator<I2, S2>& y);
4237
  ```
4238
 
4239
- *Preconditions:* `x.v_.valueless_by_exception()` and
4240
- `y.v_.valueless_by_exception()` are each `false`.
4241
 
4242
  *Returns:* `0` if i and j are each `1`, and otherwise
4243
  `get<`i`>(x.v_) - get<`j`>(y.v_)`, where i is `x.v_.index()` and j is
4244
  `y.v_.index()`.
4245
 
4246
  #### Customizations <a id="common.iter.cust">[[common.iter.cust]]</a>
4247
 
4248
  ``` cpp
4249
- friend constexpr iter_rvalue_reference_t<I> iter_move(const common_iterator& i)
4250
  noexcept(noexcept(ranges::iter_move(declval<const I&>())))
4251
  requires input_iterator<I>;
4252
  ```
4253
 
4254
- *Preconditions:* `holds_alternative<I>(i.v_)` is `true`.
4255
 
4256
  *Effects:* Equivalent to: `return ranges::iter_move(get<I>(i.v_));`
4257
 
4258
  ``` cpp
4259
  template<indirectly_swappable<I> I2, class S2>
4260
  friend constexpr void iter_swap(const common_iterator& x, const common_iterator<I2, S2>& y)
4261
  noexcept(noexcept(ranges::iter_swap(declval<const I&>(), declval<const I2&>())));
4262
  ```
4263
 
4264
- *Preconditions:* `holds_alternative<I>(x.v_)` and
4265
- `holds_alternative<I2>(y.v_)` are each `true`.
4266
 
4267
  *Effects:* Equivalent to
4268
  `ranges::iter_swap(get<I>(x.v_), get<I2>(y.v_))`.
4269
 
4270
  ### Default sentinel <a id="default.sentinel">[[default.sentinel]]</a>
@@ -4315,13 +4339,13 @@ namespace std {
4315
  public:
4316
  using iterator_type = I;
4317
  using value_type = iter_value_t<I>; // present only
4318
  // if I models indirectly_readable
4319
  using difference_type = iter_difference_t<I>;
4320
- using iterator_concept = typename I::iterator_concept; // present only
4321
  // if the qualified-id I::iterator_concept is valid and denotes a type
4322
- using iterator_category = typename I::iterator_category; // present only
4323
  // if the qualified-id I::iterator_category is valid and denotes a type
4324
  constexpr counted_iterator() requires default_initializable<I> = default;
4325
  constexpr counted_iterator(I x, iter_difference_t<I> n);
4326
  template<class I2>
4327
  requires convertible_to<const I2&, I>
@@ -4362,30 +4386,30 @@ namespace std {
4362
  requires random_access_iterator<I>;
4363
  template<common_with<I> I2>
4364
  friend constexpr iter_difference_t<I2> operator-(
4365
  const counted_iterator& x, const counted_iterator<I2>& y);
4366
  friend constexpr iter_difference_t<I> operator-(
4367
- const counted_iterator& x, default_sentinel_t);
4368
  friend constexpr iter_difference_t<I> operator-(
4369
- default_sentinel_t, const counted_iterator& y);
4370
  constexpr counted_iterator& operator-=(iter_difference_t<I> n)
4371
  requires random_access_iterator<I>;
4372
 
4373
  constexpr decltype(auto) operator[](iter_difference_t<I> n) const
4374
  requires random_access_iterator<I>;
4375
 
4376
  template<common_with<I> I2>
4377
  friend constexpr bool operator==(
4378
  const counted_iterator& x, const counted_iterator<I2>& y);
4379
  friend constexpr bool operator==(
4380
- const counted_iterator& x, default_sentinel_t);
4381
 
4382
  template<common_with<I> I2>
4383
  friend constexpr strong_ordering operator<=>(
4384
  const counted_iterator& x, const counted_iterator<I2>& y);
4385
 
4386
- friend constexpr iter_rvalue_reference_t<I> iter_move(const counted_iterator& i)
4387
  noexcept(noexcept(ranges::iter_move(i.current)))
4388
  requires input_iterator<I>;
4389
  template<indirectly_swappable<I> I2>
4390
  friend constexpr void iter_swap(const counted_iterator& x, const counted_iterator<I2>& y)
4391
  noexcept(noexcept(ranges::iter_swap(x.current, y.current)));
@@ -4408,11 +4432,11 @@ namespace std {
4408
 
4409
  ``` cpp
4410
  constexpr counted_iterator(I i, iter_difference_t<I> n);
4411
  ```
4412
 
4413
- *Preconditions:* `n >= 0`.
4414
 
4415
  *Effects:* Initializes `current` with `std::move(i)` and `length` with
4416
  `n`.
4417
 
4418
  ``` cpp
@@ -4460,11 +4484,11 @@ constexpr iter_difference_t<I> count() const noexcept;
4460
  constexpr decltype(auto) operator*();
4461
  constexpr decltype(auto) operator*() const
4462
  requires dereferenceable<const I>;
4463
  ```
4464
 
4465
- *Preconditions:* `length > 0` is `true`.
4466
 
4467
  *Effects:* Equivalent to: `return *current;`
4468
 
4469
  ``` cpp
4470
  constexpr auto operator->() const noexcept
@@ -4476,21 +4500,21 @@ constexpr auto operator->() const noexcept
4476
  ``` cpp
4477
  constexpr decltype(auto) operator[](iter_difference_t<I> n) const
4478
  requires random_access_iterator<I>;
4479
  ```
4480
 
4481
- *Preconditions:* `n < length`.
4482
 
4483
  *Effects:* Equivalent to: `return current[n];`
4484
 
4485
  #### Navigation <a id="counted.iter.nav">[[counted.iter.nav]]</a>
4486
 
4487
  ``` cpp
4488
  constexpr counted_iterator& operator++();
4489
  ```
4490
 
4491
- *Preconditions:* `length > 0`.
4492
 
4493
  *Effects:* Equivalent to:
4494
 
4495
  ``` cpp
4496
  ++current;
@@ -4500,11 +4524,11 @@ return *this;
4500
 
4501
  ``` cpp
4502
  constexpr decltype(auto) operator++(int);
4503
  ```
4504
 
4505
- *Preconditions:* `length > 0`.
4506
 
4507
  *Effects:* Equivalent to:
4508
 
4509
  ``` cpp
4510
  --length;
@@ -4570,11 +4594,11 @@ friend constexpr counted_iterator operator+(
4570
  ``` cpp
4571
  constexpr counted_iterator& operator+=(iter_difference_t<I> n)
4572
  requires random_access_iterator<I>;
4573
  ```
4574
 
4575
- *Preconditions:* `n <= length`.
4576
 
4577
  *Effects:* Equivalent to:
4578
 
4579
  ``` cpp
4580
  current += n;
@@ -4601,28 +4625,28 @@ sequence [[counted.iterator]].
4601
 
4602
  *Effects:* Equivalent to: `return y.length - x.length;`
4603
 
4604
  ``` cpp
4605
  friend constexpr iter_difference_t<I> operator-(
4606
- const counted_iterator& x, default_sentinel_t);
4607
  ```
4608
 
4609
  *Effects:* Equivalent to: `return -x.length;`
4610
 
4611
  ``` cpp
4612
  friend constexpr iter_difference_t<I> operator-(
4613
- default_sentinel_t, const counted_iterator& y);
4614
  ```
4615
 
4616
  *Effects:* Equivalent to: `return y.length;`
4617
 
4618
  ``` cpp
4619
  constexpr counted_iterator& operator-=(iter_difference_t<I> n)
4620
  requires random_access_iterator<I>;
4621
  ```
4622
 
4623
- *Preconditions:* `-n <= length`.
4624
 
4625
  *Effects:* Equivalent to:
4626
 
4627
  ``` cpp
4628
  current -= n;
@@ -4643,11 +4667,11 @@ sequence [[counted.iterator]].
4643
 
4644
  *Effects:* Equivalent to: `return x.length == y.length;`
4645
 
4646
  ``` cpp
4647
  friend constexpr bool operator==(
4648
- const counted_iterator& x, default_sentinel_t);
4649
  ```
4650
 
4651
  *Effects:* Equivalent to: `return x.length == 0;`
4652
 
4653
  ``` cpp
@@ -4665,28 +4689,28 @@ sequence [[counted.iterator]].
4665
  because `length` counts down, not up. — *end note*]
4666
 
4667
  #### Customizations <a id="counted.iter.cust">[[counted.iter.cust]]</a>
4668
 
4669
  ``` cpp
4670
- friend constexpr iter_rvalue_reference_t<I>
4671
  iter_move(const counted_iterator& i)
4672
  noexcept(noexcept(ranges::iter_move(i.current)))
4673
  requires input_iterator<I>;
4674
  ```
4675
 
4676
- *Preconditions:* `i.length > 0` is `true`.
4677
 
4678
  *Effects:* Equivalent to: `return ranges::iter_move(i.current);`
4679
 
4680
  ``` cpp
4681
  template<indirectly_swappable<I> I2>
4682
  friend constexpr void
4683
  iter_swap(const counted_iterator& x, const counted_iterator<I2>& y)
4684
  noexcept(noexcept(ranges::iter_swap(x.current, y.current)));
4685
  ```
4686
 
4687
- *Preconditions:* Both `x.length > 0` and `y.length > 0` are `true`.
4688
 
4689
  *Effects:* Equivalent to `ranges::iter_swap(x.current, y.current)`.
4690
 
4691
  ### Unreachable sentinel <a id="unreachable.sentinel">[[unreachable.sentinel]]</a>
4692
 
@@ -5003,16 +5027,16 @@ namespace std {
5003
  template<class charT, class traits = char_traits<charT>>
5004
  class istreambuf_iterator {
5005
  public:
5006
  using iterator_category = input_iterator_tag;
5007
  using value_type = charT;
5008
- using difference_type = typename traits::off_type;
5009
  using pointer = unspecified;
5010
  using reference = charT;
5011
  using char_type = charT;
5012
  using traits_type = traits;
5013
- using int_type = typename traits::int_type;
5014
  using streambuf_type = basic_streambuf<charT,traits>;
5015
  using istream_type = basic_istream<charT,traits>;
5016
 
5017
  // [istreambuf.iterator.proxy], class istreambuf_iterator::proxy
5018
  class proxy; // exposition only
@@ -5226,14 +5250,14 @@ bool failed() const noexcept;
5226
 
5227
  ## Range access <a id="iterator.range">[[iterator.range]]</a>
5228
 
5229
  In addition to being available via inclusion of the `<iterator>` header,
5230
  the function templates in [[iterator.range]] are available when any of
5231
- the following headers are included: `<array>`, `<deque>`,
5232
- `<forward_list>`, `<list>`, `<map>`, `<regex>`, `<set>`, `<span>`,
5233
- `<string>`, `<string_view>`, `<unordered_map>`, `<unordered_set>`, and
5234
- `<vector>`.
5235
 
5236
  ``` cpp
5237
  template<class C> constexpr auto begin(C& c) -> decltype(c.begin());
5238
  template<class C> constexpr auto begin(const C& c) -> decltype(c.begin());
5239
  ```
@@ -5351,23 +5375,23 @@ template<class T, ptrdiff_t N> constexpr ptrdiff_t ssize(const T (&array)[N]) no
5351
  ```
5352
 
5353
  *Returns:* `N`.
5354
 
5355
  ``` cpp
5356
- template<class C> [[nodiscard]] constexpr auto empty(const C& c) -> decltype(c.empty());
5357
  ```
5358
 
5359
  *Returns:* `c.empty()`.
5360
 
5361
  ``` cpp
5362
- template<class T, size_t N> [[nodiscard]] constexpr bool empty(const T (&array)[N]) noexcept;
5363
  ```
5364
 
5365
  *Returns:* `false`.
5366
 
5367
  ``` cpp
5368
- template<class E> [[nodiscard]] constexpr bool empty(initializer_list<E> il) noexcept;
5369
  ```
5370
 
5371
  *Returns:* `il.size() == 0`.
5372
 
5373
  ``` cpp
@@ -5388,25 +5412,26 @@ template<class E> constexpr const E* data(initializer_list<E> il) noexcept;
5388
  ```
5389
 
5390
  *Returns:* `il.begin()`.
5391
 
5392
  <!-- Link reference definitions -->
 
5393
  [alg.req]: #alg.req
5394
  [alg.req.general]: #alg.req.general
5395
  [alg.req.ind.cmp]: #alg.req.ind.cmp
5396
  [alg.req.ind.copy]: #alg.req.ind.copy
5397
  [alg.req.ind.move]: #alg.req.ind.move
5398
  [alg.req.ind.swap]: #alg.req.ind.swap
5399
  [alg.req.mergeable]: #alg.req.mergeable
5400
  [alg.req.permutable]: #alg.req.permutable
5401
  [alg.req.sortable]: #alg.req.sortable
 
5402
  [back.insert.iter.ops]: #back.insert.iter.ops
5403
  [back.insert.iterator]: #back.insert.iterator
5404
  [back.inserter]: #back.inserter
5405
  [basic.fundamental]: basic.md#basic.fundamental
5406
  [basic.lookup.argdep]: basic.md#basic.lookup.argdep
5407
- [basic.lookup.unqual]: basic.md#basic.lookup.unqual
5408
  [basic.lval]: expr.md#basic.lval
5409
  [bidirectional.iterators]: #bidirectional.iterators
5410
  [bidirectionaliterator]: #bidirectionaliterator
5411
  [cmp.concept]: support.md#cmp.concept
5412
  [common.iter.access]: #common.iter.access
@@ -5436,14 +5461,14 @@ template<class E> constexpr const E* data(initializer_list<E> il) noexcept;
5436
  [cpp17.equalitycomparable]: #cpp17.equalitycomparable
5437
  [customization.point.object]: library.md#customization.point.object
5438
  [default.sentinel]: #default.sentinel
5439
  [defns.const.subexpr]: intro.md#defns.const.subexpr
5440
  [defns.projection]: intro.md#defns.projection
5441
- [expr.call]: expr.md#expr.call
5442
  [expr.const]: expr.md#expr.const
5443
  [forward.iterators]: #forward.iterators
5444
  [forwarditerator]: #forwarditerator
 
5445
  [front.insert.iter.ops]: #front.insert.iter.ops
5446
  [front.insert.iterator]: #front.insert.iterator
5447
  [front.inserter]: #front.inserter
5448
  [func.def]: utilities.md#func.def
5449
  [incrementable.traits]: #incrementable.traits
@@ -5451,10 +5476,11 @@ template<class E> constexpr const E* data(initializer_list<E> il) noexcept;
5451
  [indirectcallable.general]: #indirectcallable.general
5452
  [indirectcallable.indirectinvocable]: #indirectcallable.indirectinvocable
5453
  [indirectcallable.traits]: #indirectcallable.traits
5454
  [input.iterators]: #input.iterators
5455
  [inputiterator]: #inputiterator
 
5456
  [insert.iter.ops]: #insert.iter.ops
5457
  [insert.iterator]: #insert.iterator
5458
  [insert.iterators]: #insert.iterators
5459
  [insert.iterators.general]: #insert.iterators.general
5460
  [inserter]: #inserter
 
75
  // [iterator.concepts], iterator concepts
76
  // [iterator.concept.readable], concept indirectly_readable
77
  template<class In>
78
  concept indirectly_readable = see below; // freestanding
79
 
80
+ // [indirectcallable.traits], indirect callable traits
81
  template<indirectly_readable T>
82
  using indirect-value-t = see below; // exposition only
83
 
84
  template<indirectly_readable T>
85
  using iter_common_reference_t = // freestanding
 
160
  requires (indirectly_readable<Is> && ...) && invocable<F, iter_reference_t<Is>...>
161
  using indirect_result_t = invoke_result_t<F, iter_reference_t<Is>...>; // freestanding
162
 
163
  // [projected], projected
164
  template<indirectly_readable I, indirectly_regular_unary_invocable<I> Proj>
165
+ using projected = see below; // freestanding
166
 
167
+ template<indirectly_readable I, indirectly_regular_unary_invocable<I> Proj>
168
+ using projected_value_t = // freestanding
169
+ remove_cvref_t<invoke_result_t<Proj&, iter_value_t<I>&>>;
170
 
171
  // [alg.req], common algorithm requirements
172
  // [alg.req.ind.move], concept indirectly_movable
173
  template<class In, class Out>
174
  concept indirectly_movable = see below; // freestanding
 
313
  template<class Iterator>
314
  constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // freestanding
315
 
316
  template<class Iterator1, class Iterator2>
317
  requires (!sized_sentinel_for<Iterator1, Iterator2>)
318
+ constexpr bool \libspec{disable_sized_sentinel_for}{reverse_iterator}<reverse_iterator<Iterator1>, // freestanding
319
  reverse_iterator<Iterator2>> = true;
320
 
321
  // [insert.iterators], insert iterators
322
  template<class Container> class back_insert_iterator; // freestanding
323
  template<class Container>
 
403
  template<class Iterator>
404
  constexpr move_iterator<Iterator> make_move_iterator(Iterator i); // freestanding
405
 
406
  template<class Iterator1, class Iterator2>
407
  requires (!sized_sentinel_for<Iterator1, Iterator2>)
408
+ constexpr bool \libspec{disable_sized_sentinel_for}{move_iterator}<move_iterator<Iterator1>, // freestanding
409
  move_iterator<Iterator2>> = true;
410
 
411
  template<semiregular S> class move_sentinel; // freestanding
412
 
413
  // [iterators.common], common iterators
 
491
  ssize(const C& c)
492
  -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // freestanding
493
  template<class T, ptrdiff_t N> constexpr ptrdiff_t
494
  ssize(const T (&array)[N]) noexcept; // freestanding
495
 
496
+ template<class C> constexpr auto
497
  empty(const C& c) -> decltype(c.empty()); // freestanding
498
+ template<class T, size_t N> constexpr bool
499
  empty(const T (&array)[N]) noexcept; // freestanding
500
+ template<class E> constexpr bool
501
  empty(initializer_list<E> il) noexcept; // freestanding
502
 
503
  template<class C> constexpr auto data(C& c) -> decltype(c.data()); // freestanding
504
  template<class C> constexpr auto data(const C& c) -> decltype(c.data()); // freestanding
505
  template<class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // freestanding
 
507
  }
508
  ```
509
 
510
  ## Iterator requirements <a id="iterator.requirements">[[iterator.requirements]]</a>
511
 
512
+ ### General <a id="iterator.requirements.general">[[iterator.requirements.general]]</a>
513
 
514
  Iterators are a generalization of pointers that allow a C++ program to
515
  work with different data structures (for example, containers and ranges)
516
  in a uniform manner. To be able to construct template algorithms that
517
  work correctly and efficiently on different types of data structures,
518
  the library formalizes not just the interfaces but also the semantics
519
  and complexity assumptions of iterators. An input iterator `i` supports
520
  the expression `*i`, resulting in a value of some object type `T`,
521
  called the *value type* of the iterator. An output iterator `i` has a
522
+ non-empty set of types that are *writable* to the iterator; for each
523
+ such type `T`, the expression `*i = o` is valid where `o` is a value of
524
+ type `T`. For every iterator type `X`, there is a corresponding signed
525
+ integer-like type [[iterator.concept.winc]] called the *difference type*
526
+ of the iterator.
527
 
528
  Since iterators are an abstraction of pointers, their semantics are a
529
  generalization of most of the semantics of pointers in C++. This ensures
530
  that every function template that takes iterators works as well with
531
  regular pointers. This document defines six categories of iterators,
 
622
  is positive, `i` is dereferenceable, and `++i`+\[0, `–n`) is valid.
623
 
624
  The result of the application of library functions to invalid ranges is
625
  undefined.
626
 
627
+ For an iterator `i` of a type that models `contiguous_iterator`
628
+ [[iterator.concept.contiguous]], library functions are permitted to
629
+ replace \[`i`, `s`) with \[`to_address(i)`,
630
+ `to_address(i + ranges::distance(i, s))`), and to replace `i`+\[0, `n`)
631
+ with \[`to_address(i)`, `to_address(i + n)`).
632
+
633
+ [*Note 3*: This means a program cannot rely on any side effects of
634
+ dereferencing a contiguous iterator `i`, because library functions might
635
+ operate on pointers obtained by `to_address(i)` instead of operating on
636
+ `i`. Similarly, a program cannot rely on any side effects of individual
637
+ increments on a contiguous iterator `i`, because library functions might
638
+ advance `i` only once. — *end note*]
639
+
640
  All the categories of iterators require only those functions that are
641
  realizable for a given category in constant time (amortized). Therefore,
642
  requirement tables and concept definitions for the iterators do not
643
  specify complexity.
644
 
645
+ Destruction of an iterator may invalidate pointers and references
646
+ previously obtained from that iterator if its type does not meet the
647
+ *Cpp17ForwardIterator* requirements and does not model
648
+ `forward_iterator`.
649
 
650
  An *invalid iterator* is an iterator that may be singular.[^2]
651
 
652
+ Iterators meet the *constexpr iterator* requirements if all operations
653
+ provided to meet iterator category requirements are constexpr functions.
654
 
655
+ [*Note 4*: For example, the types “pointer to `int`” and
656
+ `reverse_iterator<int*>` meet the constexpr iterator
657
+ requirements. — *end note*]
658
 
659
  ### Associated types <a id="iterator.assoc.types">[[iterator.assoc.types]]</a>
660
 
661
  #### Incrementable traits <a id="incrementable.traits">[[incrementable.traits]]</a>
662
 
 
687
  : incrementable_traits<I> { };
688
 
689
  template<class T>
690
  requires requires { typename T::difference_type; }
691
  struct incrementable_traits<T> {
692
+ using difference_type = T::difference_type;
693
  };
694
 
695
  template<class T>
696
  requires (!requires { typename T::difference_type; } &&
697
  requires(const T& a, const T& b) { { a - b } -> integral; })
 
892
 
893
  - If `I` has valid [[temp.deduct]] member types `difference_type`,
894
  `value_type`, `reference`, and `iterator_category`, then
895
  `iterator_traits<I>` has the following publicly accessible members:
896
  ``` cpp
897
+ using iterator_category = I::iterator_category;
898
+ using value_type = I::value_type;
899
+ using difference_type = I::difference_type;
900
  using pointer = see below;
901
+ using reference = I::reference;
902
  ```
903
 
904
  If the *qualified-id* `I::pointer` is valid and denotes a type, then
905
  `iterator_traits<I>::pointer` names that type; otherwise, it names
906
  `void`.
907
  - Otherwise, if `I` satisfies the exposition-only concept
908
  `cpp17-input-iterator`, `iterator_traits<I>` has the following
909
  publicly accessible members:
910
  ``` cpp
911
  using iterator_category = see below;
912
+ using value_type = indirectly_readable_traits<I>::value_type;
913
+ using difference_type = incrementable_traits<I>::difference_type;
914
  using pointer = see below;
915
  using reference = see below;
916
  ```
917
 
918
  - If the *qualified-id* `I::pointer` is valid and denotes a type,
 
982
  following:
983
 
984
  ``` cpp
985
  template<class BI>
986
  void reverse(BI first, BI last) {
987
+ typename iterator_traits<BI>::difference_type n = distance(first, last);
 
988
  --n;
989
  while (n > 0) {
990
+ typename iterator_traits<BI>::value_type tmp = *first;
 
991
  *first++ = *--last;
992
  *last = tmp;
993
  n -= 2;
994
  }
995
  }
 
1024
 
1025
  The name `ranges::iter_swap` denotes a customization point object
1026
  [[customization.point.object]] that exchanges the values
1027
  [[concept.swappable]] denoted by its arguments.
1028
 
1029
+ Let *`iter-exchange-move`* be the exposition-only function template:
1030
 
1031
  ``` cpp
1032
  template<class X, class Y>
1033
  constexpr iter_value_t<X> iter-exchange-move(X&& x, Y&& y)
1034
  noexcept(noexcept(iter_value_t<X>(iter_move(x))) &&
 
1124
  `indirectly_readable` concept, including pointers, smart pointers, and
1125
  iterators.
1126
 
1127
  ``` cpp
1128
  template<class In>
1129
+ concept indirectly-readable-impl = // exposition only
1130
  requires(const In in) {
1131
  typename iter_value_t<In>;
1132
  typename iter_reference_t<In>;
1133
  typename iter_rvalue_reference_t<In>;
1134
  { *in } -> same_as<iter_reference_t<In>>;
 
1166
  };
1167
  ```
1168
 
1169
  Let `E` be an expression such that `decltype((E))` is `T`, and let `o`
1170
  be a dereferenceable object of type `Out`. `Out` and `T` model
1171
+ `indirectly_writable<Out, T>` only if:
1172
 
1173
  - If `Out` and `T` model
1174
  `indirectly_readable<Out> && same_as<iter_value_t<Out>, decay_t<T>>`,
1175
  then `*o` after any above assignment is equal to the value of `E`
1176
  before the assignment.
 
1319
  type. `is-signed-integer-like<I>` is `true` if and only if `I` is a
1320
  signed-integer-like type.
1321
 
1322
  Let `i` be an object of type `I`. When `i` is in the domain of both pre-
1323
  and post-increment, `i` is said to be *incrementable*. `I` models
1324
+ `weakly_incrementable<I>` only if:
1325
 
1326
  - The expressions `++i` and `i++` have the same domain.
1327
  - If `i` is incrementable, then both `++i` and `i++` advance `i` to the
1328
  next element.
1329
  - If `i` is incrementable, then `addressof(++i)` is equal to
1330
  `addressof(i)`.
1331
 
1332
+ *Recommended practice:* The implementation of an algorithm on a weakly
1333
  incrementable type should never attempt to pass through the same
1334
  incrementable value twice; such an algorithm should be a single-pass
1335
  algorithm.
1336
 
1337
  [*Note 3*: For `weakly_incrementable` types, `a` equals `b` does not
 
1345
  The `incrementable` concept specifies requirements on types that can be
1346
  incremented with the pre- and post-increment operators. The increment
1347
  operations are required to be equality-preserving, and the type is
1348
  required to be `equality_comparable`.
1349
 
1350
+ [*Note 1*: This supersedes the “not required to be equality-preserving”
1351
+ comments on the increment expressions in the definition of
1352
+ `weakly_incrementable`. — *end note*]
1353
 
1354
  ``` cpp
1355
  template<class I>
1356
  concept incrementable =
1357
  regular<I> &&
 
1360
  { i++ } -> same_as<I>;
1361
  };
1362
  ```
1363
 
1364
  Let `a` and `b` be incrementable objects of type `I`. `I` models
1365
+ `incrementable` only if:
1366
 
1367
  - If `bool(a == b)` then `bool(a++ == b)`.
1368
  - If `bool(a == b)` then `bool(((void)a++, a) == ++b)`.
1369
 
1370
  [*Note 2*: The requirement that `a` equals `b` implies `++a` equals
 
1409
  input_or_output_iterator<I> &&
1410
  weakly-equality-comparable-with<S, I>; // see [concept.equalitycomparable]
1411
  ```
1412
 
1413
  Let `s` and `i` be values of type `S` and `I` such that \[`i`, `s`)
1414
+ denotes a range. Types `S` and `I` model `sentinel_for<S, I>` only if:
1415
 
1416
  - `i == s` is well-defined.
1417
  - If `bool(i != s)` then `i` is dereferenceable and \[`++i`, `s`)
1418
  denotes a range.
1419
  - `assignable_from<I&, S>` is either modeled or not satisfied.
 
1443
  ```
1444
 
1445
  Let `i` be an iterator of type `I`, and `s` a sentinel of type `S` such
1446
  that \[`i`, `s`) denotes a range. Let N be the smallest number of
1447
  applications of `++i` necessary to make `bool(i == s)` be `true`. `S`
1448
+ and `I` model `sized_sentinel_for<S, I>` only if:
1449
 
1450
  - If N is representable by `iter_difference_t<I>`, then `s - i` is
1451
  well-defined and equals N.
1452
  - If -N is representable by `iter_difference_t<I>`, then `i - s` is
1453
  well-defined and equals -N.
 
1551
  Pointers and references obtained from a forward iterator into a range
1552
  \[`i`, `s`) shall remain valid while \[`i`, `s`) continues to denote a
1553
  range.
1554
 
1555
  Two dereferenceable iterators `a` and `b` of type `X` offer the
1556
+ *multi-pass guarantee* if
1557
 
1558
  - `a == b` implies `++a == ++b` and
1559
  - the expression `((void)[](X x){++x;}(a), *a)` is equivalent to the
1560
  expression `*a`.
1561
 
 
1622
  ```
1623
 
1624
  Let `a` and `b` be valid iterators of type `I` such that `b` is
1625
  reachable from `a` after `n` applications of `++a`, let `D` be
1626
  `iter_difference_t<I>`, and let `n` denote a value of type `D`. `I`
1627
+ models `random_access_iterator` only if:
1628
 
1629
  - `(a += n)` is equal to `b`.
1630
  - `addressof(a += n)` is equal to `addressof(a)`.
1631
  - `(a + n)` is equal to `(a += n)`.
1632
  - For any two positive values `x` and `y` of type `D`, if
 
1666
  if
1667
 
1668
  - `to_address(a) == addressof(*a)`,
1669
  - `to_address(b) == to_address(a) + D(b - a)`,
1670
  - `to_address(c) == to_address(a) + D(c - a)`,
1671
+ - `to_address(I{})` is well-defined,
1672
  - `ranges::iter_move(a)` has the same type, value category, and effects
1673
  as `std::move(*a)`, and
1674
  - if `ranges::iter_swap(a, b)` is well-formed, it has effects equivalent
1675
  to `ranges::swap(*a, *b)`.
1676
 
 
1697
  incrementing an iterator. Most algorithms will require additional
1698
  operations to read [[input.iterators]] or write [[output.iterators]]
1699
  values, or to provide a richer set of iterator movements
1700
  [[forward.iterators]], [[bidirectional.iterators]], [[random.access.iterators]].
1701
 
1702
+ A type `X` meets the requirements if
1703
 
1704
  - `X` meets the *Cpp17CopyConstructible*, *Cpp17CopyAssignable*,
1705
  *Cpp17Swappable*, and *Cpp17Destructible* requirements
1706
  [[utility.arg.requirements]], [[swappable.requirements]], and
1707
  - `iterator_traits<X>::difference_type` is a signed integer type or
 
1756
  iterator happens only once. Equality and inequality are not necessarily
1757
  defined. — *end note*]
1758
 
1759
  #### Forward iterators <a id="forward.iterators">[[forward.iterators]]</a>
1760
 
1761
+ A class or pointer type `X` meets the *Cpp17ForwardIterator*
1762
+ requirements if
1763
 
1764
  - `X` meets the *Cpp17InputIterator* requirements [[input.iterators]],
1765
  - `X` meets the *Cpp17DefaultConstructible* requirements
1766
  [[utility.arg.requirements]],
1767
  - if `X` is a mutable iterator, `reference` is a reference to `T`; if
 
1777
 
1778
  [*Note 1*: Value-initialized iterators behave as if they refer past the
1779
  end of the same empty sequence. — *end note*]
1780
 
1781
  Two dereferenceable iterators `a` and `b` of type `X` offer the
1782
+ *multi-pass guarantee* if
1783
 
1784
  - `a == b` implies `++a == ++b` and
1785
  - `X` is a pointer type or the expression `(void)++X(a), *a` is
1786
  equivalent to the expression `*a`.
1787
 
 
1842
  concept indirectly_unary_invocable =
1843
  indirectly_readable<I> &&
1844
  copy_constructible<F> &&
1845
  invocable<F&, indirect-value-t<I>> &&
1846
  invocable<F&, iter_reference_t<I>> &&
 
1847
  common_reference_with<
1848
  invoke_result_t<F&, indirect-value-t<I>>,
1849
  invoke_result_t<F&, iter_reference_t<I>>>;
1850
 
1851
  template<class F, class I>
1852
  concept indirectly_regular_unary_invocable =
1853
  indirectly_readable<I> &&
1854
  copy_constructible<F> &&
1855
  regular_invocable<F&, indirect-value-t<I>> &&
1856
  regular_invocable<F&, iter_reference_t<I>> &&
 
1857
  common_reference_with<
1858
  invoke_result_t<F&, indirect-value-t<I>>,
1859
  invoke_result_t<F&, iter_reference_t<I>>>;
1860
 
1861
  template<class F, class I>
1862
  concept indirect_unary_predicate =
1863
  indirectly_readable<I> &&
1864
  copy_constructible<F> &&
1865
  predicate<F&, indirect-value-t<I>> &&
1866
+ predicate<F&, iter_reference_t<I>>;
 
1867
 
1868
  template<class F, class I1, class I2>
1869
  concept indirect_binary_predicate =
1870
  indirectly_readable<I1> && indirectly_readable<I2> &&
1871
  copy_constructible<F> &&
1872
  predicate<F&, indirect-value-t<I1>, indirect-value-t<I2>> &&
1873
  predicate<F&, indirect-value-t<I1>, iter_reference_t<I2>> &&
1874
  predicate<F&, iter_reference_t<I1>, indirect-value-t<I2>> &&
1875
+ predicate<F&, iter_reference_t<I1>, iter_reference_t<I2>>;
 
1876
 
1877
  template<class F, class I1, class I2 = I1>
1878
  concept indirect_equivalence_relation =
1879
  indirectly_readable<I1> && indirectly_readable<I2> &&
1880
  copy_constructible<F> &&
1881
  equivalence_relation<F&, indirect-value-t<I1>, indirect-value-t<I2>> &&
1882
  equivalence_relation<F&, indirect-value-t<I1>, iter_reference_t<I2>> &&
1883
  equivalence_relation<F&, iter_reference_t<I1>, indirect-value-t<I2>> &&
1884
+ equivalence_relation<F&, iter_reference_t<I1>, iter_reference_t<I2>>;
 
1885
 
1886
  template<class F, class I1, class I2 = I1>
1887
  concept indirect_strict_weak_order =
1888
  indirectly_readable<I1> && indirectly_readable<I2> &&
1889
  copy_constructible<F> &&
1890
  strict_weak_order<F&, indirect-value-t<I1>, indirect-value-t<I2>> &&
1891
  strict_weak_order<F&, indirect-value-t<I1>, iter_reference_t<I2>> &&
1892
  strict_weak_order<F&, iter_reference_t<I1>, indirect-value-t<I2>> &&
1893
+ strict_weak_order<F&, iter_reference_t<I1>, iter_reference_t<I2>>;
 
1894
  }
1895
  ```
1896
 
1897
+ #### Alias template `projected` <a id="projected">[[projected]]</a>
1898
 
1899
+ Alias template `projected` is used to constrain algorithms that accept
1900
  callable objects and projections [[defns.projection]]. It combines an
1901
  `indirectly_readable` type `I` and a callable object type `Proj` into a
1902
  new `indirectly_readable` type whose `reference` type is the result of
1903
  applying `Proj` to the `iter_reference_t` of `I`.
1904
 
1905
  ``` cpp
1906
  namespace std {
1907
+ template<class I, class Proj>
1908
+ struct projected-impl { // exposition only
1909
+ struct type { // exposition only
1910
  using value_type = remove_cvref_t<indirect_result_t<Proj&, I>>;
1911
+ using difference_type = iter_difference_t<I>; // present only if I
1912
+ // models weakly_incrementable
1913
  indirect_result_t<Proj&, I> operator*() const; // not defined
1914
  };
 
 
 
 
1915
  };
1916
+
1917
+ template<indirectly_readable I, indirectly_regular_unary_invocable<I> Proj>
1918
+ using projected = projected-impl<I, Proj>::type;
1919
  }
1920
  ```
1921
 
1922
  ### Common algorithm requirements <a id="alg.req">[[alg.req]]</a>
1923
 
 
2236
  `random_access_iterator` forward `n` steps in constant time. For an
2237
  iterator type that does not model `random_access_iterator`,
2238
  `ranges::advance` instead performs `n` individual increments with the
2239
  `++` operator. — *end example*]
2240
 
2241
+ The entities defined in [[range.iter.ops]] are algorithm function
2242
+ objects [[alg.func.obj]].
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2243
 
2244
  #### `ranges::advance` <a id="range.iter.op.advance">[[range.iter.op.advance]]</a>
2245
 
2246
  ``` cpp
2247
  template<input_or_output_iterator I>
 
2315
  template<class I, sized_sentinel_for<decay_t<I>> S>
2316
  constexpr iter_difference_t<decay_t<I>> ranges::distance(I&& first, S last);
2317
  ```
2318
 
2319
  *Effects:* Equivalent to:
2320
+
2321
+ ``` cpp
2322
+ if constexpr (!is_array_v<remove_reference_t<I>>)
2323
+ return last - first;
2324
+ else
2325
+ return last - static_cast<decay_t<I>>(first);
2326
+ ```
2327
 
2328
  ``` cpp
2329
  template<range R>
2330
  constexpr range_difference_t<R> ranges::distance(R&& r);
2331
  ```
 
2415
  using iterator_type = Iterator;
2416
  using iterator_concept = see below;
2417
  using iterator_category = see below;
2418
  using value_type = iter_value_t<Iterator>;
2419
  using difference_type = iter_difference_t<Iterator>;
2420
+ using pointer = iterator_traits<Iterator>::pointer;
2421
  using reference = iter_reference_t<Iterator>;
2422
 
2423
  constexpr reverse_iterator();
2424
  constexpr explicit reverse_iterator(Iterator x);
2425
  template<class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
 
2492
 
2493
  ``` cpp
2494
  constexpr reverse_iterator();
2495
  ```
2496
 
2497
+ *Effects:* Value-initializes `current`.
 
 
 
2498
 
2499
  ``` cpp
2500
  constexpr explicit reverse_iterator(Iterator x);
2501
  ```
2502
 
 
2822
  `front_inserter`, and `inserter` are three functions making the insert
2823
  iterators out of a container.
2824
 
2825
  #### Class template `back_insert_iterator` <a id="back.insert.iterator">[[back.insert.iterator]]</a>
2826
 
2827
+ ##### General <a id="back.insert.iter.general">[[back.insert.iter.general]]</a>
2828
+
2829
  ``` cpp
2830
  namespace std {
2831
  template<class Container>
2832
  class back_insert_iterator {
2833
  protected:
 
2898
 
2899
  *Returns:* `back_insert_iterator<Container>(x)`.
2900
 
2901
  #### Class template `front_insert_iterator` <a id="front.insert.iterator">[[front.insert.iterator]]</a>
2902
 
2903
+ ##### General <a id="front.insert.iter.general">[[front.insert.iter.general]]</a>
2904
+
2905
  ``` cpp
2906
  namespace std {
2907
  template<class Container>
2908
  class front_insert_iterator {
2909
  protected:
 
2974
 
2975
  *Returns:* `front_insert_iterator<Container>(x)`.
2976
 
2977
  #### Class template `insert_iterator` <a id="insert.iterator">[[insert.iterator]]</a>
2978
 
2979
+ ##### General <a id="insert.iter.general">[[insert.iter.general]]</a>
2980
+
2981
  ``` cpp
2982
  namespace std {
2983
  template<class Container>
2984
  class insert_iterator {
2985
  protected:
 
3158
  requires random_access_iterator<Iterator>;
3159
 
3160
  template<sentinel_for<Iterator> S>
3161
  constexpr bool operator==(const S& s) const;
3162
 
3163
+ template<not-a-const-iterator CI>
3164
+ requires constant-iterator<CI> && convertible_to<Iterator const&, CI>
3165
+ constexpr operator CI() const &;
3166
+ template<not-a-const-iterator CI>
3167
+ requires constant-iterator<CI> && convertible_to<Iterator, CI>
3168
+ constexpr operator CI() &&;
3169
+
3170
  constexpr bool operator<(const basic_const_iterator& y) const
3171
  requires random_access_iterator<Iterator>;
3172
  constexpr bool operator>(const basic_const_iterator& y) const
3173
  requires random_access_iterator<Iterator>;
3174
  constexpr bool operator<=(const basic_const_iterator& y) const
 
3386
  constexpr bool operator==(const S& s) const;
3387
  ```
3388
 
3389
  *Effects:* Equivalent to: `return `*`current_`*` == s;`
3390
 
3391
+ ``` cpp
3392
+ template<not-a-const-iterator CI>
3393
+ requires constant-iterator<CI> && convertible_to<Iterator const&, CI>
3394
+ constexpr operator CI() const &;
3395
+ ```
3396
+
3397
+ *Returns:* *current\_*.
3398
+
3399
+ ``` cpp
3400
+ template<not-a-const-iterator CI>
3401
+ requires constant-iterator<CI> && convertible_to<Iterator, CI>
3402
+ constexpr operator CI() &&;
3403
+ ```
3404
+
3405
+ *Returns:* `std::move(`*`current_`*`)`.
3406
+
3407
  ``` cpp
3408
  constexpr bool operator<(const basic_const_iterator& y) const
3409
  requires random_access_iterator<Iterator>;
3410
  constexpr bool operator>(const basic_const_iterator& y) const
3411
  requires random_access_iterator<Iterator>;
 
3460
  requires random_access_iterator<Iterator> && totally_ordered_with<Iterator, I>;
3461
  ```
3462
 
3463
  Let *`op`* be the operator.
3464
 
3465
+ *Effects:* Equivalent to: `return x `*`op`*` y.`*`current_`*`;`
3466
 
3467
  ``` cpp
3468
  friend constexpr basic_const_iterator operator+(const basic_const_iterator& i, difference_type n)
3469
  requires random_access_iterator<Iterator>;
3470
  friend constexpr basic_const_iterator operator+(difference_type n, const basic_const_iterator& i)
 
4014
  template<sized_sentinel_for<I> I2, sized_sentinel_for<I> S2>
4015
  requires sized_sentinel_for<S, I2>
4016
  friend constexpr iter_difference_t<I2> operator-(
4017
  const common_iterator& x, const common_iterator<I2, S2>& y);
4018
 
4019
+ friend constexpr decltype(auto) iter_move(const common_iterator& i)
4020
  noexcept(noexcept(ranges::iter_move(declval<const I&>())))
4021
  requires input_iterator<I>;
4022
  template<indirectly_swappable<I> I2, class S2>
4023
  friend constexpr void iter_swap(const common_iterator& x, const common_iterator<I2, S2>& y)
4024
  noexcept(noexcept(ranges::iter_swap(declval<const I&>(), declval<const I2&>())));
 
4033
  };
4034
 
4035
  template<input_iterator I, class S>
4036
  struct iterator_traits<common_iterator<I, S>> {
4037
  using iterator_concept = see below;
4038
+ using iterator_category = see below; // not always present
4039
  using value_type = iter_value_t<I>;
4040
  using difference_type = iter_difference_t<I>;
4041
  using pointer = see below;
4042
  using reference = iter_reference_t<I>;
4043
  };
4044
  }
4045
  ```
4046
 
4047
  #### Associated types <a id="common.iter.types">[[common.iter.types]]</a>
4048
 
4049
+ The nested *typedef-name* `iterator_category` of the specialization of
4050
+ `iterator_traits` for `common_iterator<I, S>` is defined if and only if
4051
+ `iter_difference_t<I>` is an integral type. In that case,
4052
+ `iterator_category` denotes `forward_iterator_tag` if the *qualified-id*
4053
+ `iterator_traits<I>::iterator_category` is valid and denotes a type that
4054
+ models `derived_from<forward_iterator_tag>`; otherwise it denotes
4055
+ `input_iterator_tag`.
4056
+
4057
+ The remaining nested *typedef-name*s of the specialization of
4058
+ `iterator_traits` for `common_iterator<I, S>` are defined as follows:
4059
 
4060
  - `iterator_concept` denotes `forward_iterator_tag` if `I` models
4061
  `forward_iterator`; otherwise it denotes `input_iterator_tag`.
 
 
 
 
4062
  - Let `a` denote an lvalue of type `const common_iterator<I, S>`. If the
4063
  expression `a.operator->()` is well-formed, then `pointer` denotes
4064
  `decltype(a.operator->())`. Otherwise, `pointer` denotes `void`.
4065
 
4066
  #### Constructors and conversions <a id="common.iter.const">[[common.iter.const]]</a>
 
4083
  template<class I2, class S2>
4084
  requires convertible_to<const I2&, I> && convertible_to<const S2&, S>
4085
  constexpr common_iterator(const common_iterator<I2, S2>& x);
4086
  ```
4087
 
4088
+ `x.v_.valueless_by_exception()` is `false`.
4089
 
4090
  *Effects:* Initializes `v_` as if by
4091
  `v_{in_place_index<`i`>, get<`i`>(x.v_)}`, where i is `x.v_.index()`.
4092
 
4093
  ``` cpp
 
4095
  requires convertible_to<const I2&, I> && convertible_to<const S2&, S> &&
4096
  assignable_from<I&, const I2&> && assignable_from<S&, const S2&>
4097
  constexpr common_iterator& operator=(const common_iterator<I2, S2>& x);
4098
  ```
4099
 
4100
+ `x.v_.valueless_by_exception()` is `false`.
4101
 
4102
  *Effects:* Equivalent to:
4103
 
4104
  - If `v_.index() == x.v_.index()`, then `get<`i`>(v_) = get<`i`>(x.v_)`.
4105
  - Otherwise, `v_.emplace<`i`>(get<`i`>(x.v_))`.
4106
 
4107
  where i is `x.v_.index()`.
4108
 
4109
+ *Returns:* `*this`.
4110
 
4111
  #### Accessors <a id="common.iter.access">[[common.iter.access]]</a>
4112
 
4113
  ``` cpp
4114
  constexpr decltype(auto) operator*();
4115
  constexpr decltype(auto) operator*() const
4116
  requires dereferenceable<const I>;
4117
  ```
4118
 
4119
+ `holds_alternative<I>(v_)` is `true`.
4120
 
4121
  *Effects:* Equivalent to: `return *get<I>(v_);`
4122
 
4123
  ``` cpp
4124
  constexpr auto operator->() const
 
4132
  (requires(const I& i) { i.operator->(); } ||
4133
  is_reference_v<iter_reference_t<I>> ||
4134
  constructible_from<iter_value_t<I>, iter_reference_t<I>>)
4135
  ```
4136
 
4137
+ `holds_alternative<I>(v_)` is `true`.
4138
 
4139
  *Effects:*
4140
 
4141
  - If `I` is a pointer type or if the expression
4142
  `get<I>(v_).operator->()` is well-formed, equivalent to:
 
4165
 
4166
  ``` cpp
4167
  constexpr common_iterator& operator++();
4168
  ```
4169
 
4170
+ `holds_alternative<I>(v_)` is `true`.
4171
 
4172
  *Effects:* Equivalent to `++get<I>(v_)`.
4173
 
4174
  *Returns:* `*this`.
4175
 
4176
  ``` cpp
4177
  constexpr decltype(auto) operator++(int);
4178
  ```
4179
 
4180
+ `holds_alternative<I>(v_)` is `true`.
4181
 
4182
  *Effects:* If `I` models `forward_iterator`, equivalent to:
4183
 
4184
  ``` cpp
4185
  common_iterator tmp = *this;
 
4230
  requires sentinel_for<S, I2>
4231
  friend constexpr bool operator==(
4232
  const common_iterator& x, const common_iterator<I2, S2>& y);
4233
  ```
4234
 
4235
+ `x.v_.valueless_by_exception()` and `y.v_.valueless_by_exception()` are
4236
+ each `false`.
4237
 
4238
  *Returns:* `true` if i` == `j, and otherwise
4239
  `get<`i`>(x.v_) == get<`j`>(y.v_)`, where i is `x.v_.index()` and j is
4240
  `y.v_.index()`.
4241
 
 
4244
  requires sentinel_for<S, I2> && equality_comparable_with<I, I2>
4245
  friend constexpr bool operator==(
4246
  const common_iterator& x, const common_iterator<I2, S2>& y);
4247
  ```
4248
 
4249
+ `x.v_.valueless_by_exception()` and `y.v_.valueless_by_exception()` are
4250
+ each `false`.
4251
 
4252
  *Returns:* `true` if i and j are each `1`, and otherwise
4253
  `get<`i`>(x.v_) == get<`j`>(y.v_)`, where i is `x.v_.index()` and j is
4254
  `y.v_.index()`.
4255
 
 
4258
  requires sized_sentinel_for<S, I2>
4259
  friend constexpr iter_difference_t<I2> operator-(
4260
  const common_iterator& x, const common_iterator<I2, S2>& y);
4261
  ```
4262
 
4263
+ `x.v_.valueless_by_exception()` and `y.v_.valueless_by_exception()` are
4264
+ each `false`.
4265
 
4266
  *Returns:* `0` if i and j are each `1`, and otherwise
4267
  `get<`i`>(x.v_) - get<`j`>(y.v_)`, where i is `x.v_.index()` and j is
4268
  `y.v_.index()`.
4269
 
4270
  #### Customizations <a id="common.iter.cust">[[common.iter.cust]]</a>
4271
 
4272
  ``` cpp
4273
+ friend constexpr decltype(auto) iter_move(const common_iterator& i)
4274
  noexcept(noexcept(ranges::iter_move(declval<const I&>())))
4275
  requires input_iterator<I>;
4276
  ```
4277
 
4278
+ `holds_alternative<I>(i.v_)` is `true`.
4279
 
4280
  *Effects:* Equivalent to: `return ranges::iter_move(get<I>(i.v_));`
4281
 
4282
  ``` cpp
4283
  template<indirectly_swappable<I> I2, class S2>
4284
  friend constexpr void iter_swap(const common_iterator& x, const common_iterator<I2, S2>& y)
4285
  noexcept(noexcept(ranges::iter_swap(declval<const I&>(), declval<const I2&>())));
4286
  ```
4287
 
4288
+ `holds_alternative<I>(x.v_)` and `holds_alternative<I2>(y.v_)` are each
4289
+ `true`.
4290
 
4291
  *Effects:* Equivalent to
4292
  `ranges::iter_swap(get<I>(x.v_), get<I2>(y.v_))`.
4293
 
4294
  ### Default sentinel <a id="default.sentinel">[[default.sentinel]]</a>
 
4339
  public:
4340
  using iterator_type = I;
4341
  using value_type = iter_value_t<I>; // present only
4342
  // if I models indirectly_readable
4343
  using difference_type = iter_difference_t<I>;
4344
+ using iterator_concept = I::iterator_concept; // present only
4345
  // if the qualified-id I::iterator_concept is valid and denotes a type
4346
+ using iterator_category = I::iterator_category; // present only
4347
  // if the qualified-id I::iterator_category is valid and denotes a type
4348
  constexpr counted_iterator() requires default_initializable<I> = default;
4349
  constexpr counted_iterator(I x, iter_difference_t<I> n);
4350
  template<class I2>
4351
  requires convertible_to<const I2&, I>
 
4386
  requires random_access_iterator<I>;
4387
  template<common_with<I> I2>
4388
  friend constexpr iter_difference_t<I2> operator-(
4389
  const counted_iterator& x, const counted_iterator<I2>& y);
4390
  friend constexpr iter_difference_t<I> operator-(
4391
+ const counted_iterator& x, default_sentinel_t) noexcept;
4392
  friend constexpr iter_difference_t<I> operator-(
4393
+ default_sentinel_t, const counted_iterator& y) noexcept;
4394
  constexpr counted_iterator& operator-=(iter_difference_t<I> n)
4395
  requires random_access_iterator<I>;
4396
 
4397
  constexpr decltype(auto) operator[](iter_difference_t<I> n) const
4398
  requires random_access_iterator<I>;
4399
 
4400
  template<common_with<I> I2>
4401
  friend constexpr bool operator==(
4402
  const counted_iterator& x, const counted_iterator<I2>& y);
4403
  friend constexpr bool operator==(
4404
+ const counted_iterator& x, default_sentinel_t) noexcept;
4405
 
4406
  template<common_with<I> I2>
4407
  friend constexpr strong_ordering operator<=>(
4408
  const counted_iterator& x, const counted_iterator<I2>& y);
4409
 
4410
+ friend constexpr decltype(auto) iter_move(const counted_iterator& i)
4411
  noexcept(noexcept(ranges::iter_move(i.current)))
4412
  requires input_iterator<I>;
4413
  template<indirectly_swappable<I> I2>
4414
  friend constexpr void iter_swap(const counted_iterator& x, const counted_iterator<I2>& y)
4415
  noexcept(noexcept(ranges::iter_swap(x.current, y.current)));
 
4432
 
4433
  ``` cpp
4434
  constexpr counted_iterator(I i, iter_difference_t<I> n);
4435
  ```
4436
 
4437
+ `n >= 0` is `true`.
4438
 
4439
  *Effects:* Initializes `current` with `std::move(i)` and `length` with
4440
  `n`.
4441
 
4442
  ``` cpp
 
4484
  constexpr decltype(auto) operator*();
4485
  constexpr decltype(auto) operator*() const
4486
  requires dereferenceable<const I>;
4487
  ```
4488
 
4489
+ `length > 0` is `true`.
4490
 
4491
  *Effects:* Equivalent to: `return *current;`
4492
 
4493
  ``` cpp
4494
  constexpr auto operator->() const noexcept
 
4500
  ``` cpp
4501
  constexpr decltype(auto) operator[](iter_difference_t<I> n) const
4502
  requires random_access_iterator<I>;
4503
  ```
4504
 
4505
+ `n < length` is `true`.
4506
 
4507
  *Effects:* Equivalent to: `return current[n];`
4508
 
4509
  #### Navigation <a id="counted.iter.nav">[[counted.iter.nav]]</a>
4510
 
4511
  ``` cpp
4512
  constexpr counted_iterator& operator++();
4513
  ```
4514
 
4515
+ `length > 0` is `true`.
4516
 
4517
  *Effects:* Equivalent to:
4518
 
4519
  ``` cpp
4520
  ++current;
 
4524
 
4525
  ``` cpp
4526
  constexpr decltype(auto) operator++(int);
4527
  ```
4528
 
4529
+ `length > 0` is `true`.
4530
 
4531
  *Effects:* Equivalent to:
4532
 
4533
  ``` cpp
4534
  --length;
 
4594
  ``` cpp
4595
  constexpr counted_iterator& operator+=(iter_difference_t<I> n)
4596
  requires random_access_iterator<I>;
4597
  ```
4598
 
4599
+ `n <= length` is `true`.
4600
 
4601
  *Effects:* Equivalent to:
4602
 
4603
  ``` cpp
4604
  current += n;
 
4625
 
4626
  *Effects:* Equivalent to: `return y.length - x.length;`
4627
 
4628
  ``` cpp
4629
  friend constexpr iter_difference_t<I> operator-(
4630
+ const counted_iterator& x, default_sentinel_t) noexcept;
4631
  ```
4632
 
4633
  *Effects:* Equivalent to: `return -x.length;`
4634
 
4635
  ``` cpp
4636
  friend constexpr iter_difference_t<I> operator-(
4637
+ default_sentinel_t, const counted_iterator& y) noexcept;
4638
  ```
4639
 
4640
  *Effects:* Equivalent to: `return y.length;`
4641
 
4642
  ``` cpp
4643
  constexpr counted_iterator& operator-=(iter_difference_t<I> n)
4644
  requires random_access_iterator<I>;
4645
  ```
4646
 
4647
+ `-n <= length` is `true`.
4648
 
4649
  *Effects:* Equivalent to:
4650
 
4651
  ``` cpp
4652
  current -= n;
 
4667
 
4668
  *Effects:* Equivalent to: `return x.length == y.length;`
4669
 
4670
  ``` cpp
4671
  friend constexpr bool operator==(
4672
+ const counted_iterator& x, default_sentinel_t) noexcept;
4673
  ```
4674
 
4675
  *Effects:* Equivalent to: `return x.length == 0;`
4676
 
4677
  ``` cpp
 
4689
  because `length` counts down, not up. — *end note*]
4690
 
4691
  #### Customizations <a id="counted.iter.cust">[[counted.iter.cust]]</a>
4692
 
4693
  ``` cpp
4694
+ friend constexpr decltype(auto)
4695
  iter_move(const counted_iterator& i)
4696
  noexcept(noexcept(ranges::iter_move(i.current)))
4697
  requires input_iterator<I>;
4698
  ```
4699
 
4700
+ `i.length > 0` is `true`.
4701
 
4702
  *Effects:* Equivalent to: `return ranges::iter_move(i.current);`
4703
 
4704
  ``` cpp
4705
  template<indirectly_swappable<I> I2>
4706
  friend constexpr void
4707
  iter_swap(const counted_iterator& x, const counted_iterator<I2>& y)
4708
  noexcept(noexcept(ranges::iter_swap(x.current, y.current)));
4709
  ```
4710
 
4711
+ Both `x.length > 0` and `y.length > 0` are `true`.
4712
 
4713
  *Effects:* Equivalent to `ranges::iter_swap(x.current, y.current)`.
4714
 
4715
  ### Unreachable sentinel <a id="unreachable.sentinel">[[unreachable.sentinel]]</a>
4716
 
 
5027
  template<class charT, class traits = char_traits<charT>>
5028
  class istreambuf_iterator {
5029
  public:
5030
  using iterator_category = input_iterator_tag;
5031
  using value_type = charT;
5032
+ using difference_type = traits::off_type;
5033
  using pointer = unspecified;
5034
  using reference = charT;
5035
  using char_type = charT;
5036
  using traits_type = traits;
5037
+ using int_type = traits::int_type;
5038
  using streambuf_type = basic_streambuf<charT,traits>;
5039
  using istream_type = basic_istream<charT,traits>;
5040
 
5041
  // [istreambuf.iterator.proxy], class istreambuf_iterator::proxy
5042
  class proxy; // exposition only
 
5250
 
5251
  ## Range access <a id="iterator.range">[[iterator.range]]</a>
5252
 
5253
  In addition to being available via inclusion of the `<iterator>` header,
5254
  the function templates in [[iterator.range]] are available when any of
5255
+ the following headers are included: `<array>`, `<deque>`, `<flat_map>`,
5256
+ `<flat_set>`, `<forward_list>`, `<hive>`, `<inplace_vector>`, `<list>`,
5257
+ `<map>`, `<regex>`, `<set>`, `<span>`, `<string>`, `<string_view>`,
5258
+ `<unordered_map>`, `<unordered_set>`, and `<vector>`.
5259
 
5260
  ``` cpp
5261
  template<class C> constexpr auto begin(C& c) -> decltype(c.begin());
5262
  template<class C> constexpr auto begin(const C& c) -> decltype(c.begin());
5263
  ```
 
5375
  ```
5376
 
5377
  *Returns:* `N`.
5378
 
5379
  ``` cpp
5380
+ template<class C> constexpr auto empty(const C& c) -> decltype(c.empty());
5381
  ```
5382
 
5383
  *Returns:* `c.empty()`.
5384
 
5385
  ``` cpp
5386
+ template<class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept;
5387
  ```
5388
 
5389
  *Returns:* `false`.
5390
 
5391
  ``` cpp
5392
+ template<class E> constexpr bool empty(initializer_list<E> il) noexcept;
5393
  ```
5394
 
5395
  *Returns:* `il.size() == 0`.
5396
 
5397
  ``` cpp
 
5412
  ```
5413
 
5414
  *Returns:* `il.begin()`.
5415
 
5416
  <!-- Link reference definitions -->
5417
+ [alg.func.obj]: library.md#alg.func.obj
5418
  [alg.req]: #alg.req
5419
  [alg.req.general]: #alg.req.general
5420
  [alg.req.ind.cmp]: #alg.req.ind.cmp
5421
  [alg.req.ind.copy]: #alg.req.ind.copy
5422
  [alg.req.ind.move]: #alg.req.ind.move
5423
  [alg.req.ind.swap]: #alg.req.ind.swap
5424
  [alg.req.mergeable]: #alg.req.mergeable
5425
  [alg.req.permutable]: #alg.req.permutable
5426
  [alg.req.sortable]: #alg.req.sortable
5427
+ [back.insert.iter.general]: #back.insert.iter.general
5428
  [back.insert.iter.ops]: #back.insert.iter.ops
5429
  [back.insert.iterator]: #back.insert.iterator
5430
  [back.inserter]: #back.inserter
5431
  [basic.fundamental]: basic.md#basic.fundamental
5432
  [basic.lookup.argdep]: basic.md#basic.lookup.argdep
 
5433
  [basic.lval]: expr.md#basic.lval
5434
  [bidirectional.iterators]: #bidirectional.iterators
5435
  [bidirectionaliterator]: #bidirectionaliterator
5436
  [cmp.concept]: support.md#cmp.concept
5437
  [common.iter.access]: #common.iter.access
 
5461
  [cpp17.equalitycomparable]: #cpp17.equalitycomparable
5462
  [customization.point.object]: library.md#customization.point.object
5463
  [default.sentinel]: #default.sentinel
5464
  [defns.const.subexpr]: intro.md#defns.const.subexpr
5465
  [defns.projection]: intro.md#defns.projection
 
5466
  [expr.const]: expr.md#expr.const
5467
  [forward.iterators]: #forward.iterators
5468
  [forwarditerator]: #forwarditerator
5469
+ [front.insert.iter.general]: #front.insert.iter.general
5470
  [front.insert.iter.ops]: #front.insert.iter.ops
5471
  [front.insert.iterator]: #front.insert.iterator
5472
  [front.inserter]: #front.inserter
5473
  [func.def]: utilities.md#func.def
5474
  [incrementable.traits]: #incrementable.traits
 
5476
  [indirectcallable.general]: #indirectcallable.general
5477
  [indirectcallable.indirectinvocable]: #indirectcallable.indirectinvocable
5478
  [indirectcallable.traits]: #indirectcallable.traits
5479
  [input.iterators]: #input.iterators
5480
  [inputiterator]: #inputiterator
5481
+ [insert.iter.general]: #insert.iter.general
5482
  [insert.iter.ops]: #insert.iter.ops
5483
  [insert.iterator]: #insert.iterator
5484
  [insert.iterators]: #insert.iterators
5485
  [insert.iterators.general]: #insert.iterators.general
5486
  [inserter]: #inserter