- tmp/tmpobt86hml/{from.md → to.md} +427 -73
tmp/tmpobt86hml/{from.md → to.md}
RENAMED
|
@@ -1,22 +1,24 @@
|
|
| 1 |
## Range factories <a id="range.factories">[[range.factories]]</a>
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
| 5 |
|
| 6 |
Range factories are declared in namespace `std::ranges::views`.
|
| 7 |
|
| 8 |
### Empty view <a id="range.empty">[[range.empty]]</a>
|
| 9 |
|
| 10 |
#### Overview <a id="range.empty.overview">[[range.empty.overview]]</a>
|
| 11 |
|
| 12 |
-
`empty_view` produces a
|
| 13 |
|
| 14 |
[*Example 1*:
|
| 15 |
|
| 16 |
``` cpp
|
| 17 |
-
|
| 18 |
static_assert(ranges::empty(e));
|
| 19 |
static_assert(0 == e.size());
|
| 20 |
```
|
| 21 |
|
| 22 |
— *end example*]
|
|
@@ -40,58 +42,61 @@ namespace std::ranges {
|
|
| 40 |
|
| 41 |
### Single view <a id="range.single">[[range.single]]</a>
|
| 42 |
|
| 43 |
#### Overview <a id="range.single.overview">[[range.single.overview]]</a>
|
| 44 |
|
| 45 |
-
`single_view` produces a
|
| 46 |
specified value.
|
| 47 |
|
| 48 |
The name `views::single` denotes a customization point object
|
| 49 |
[[customization.point.object]]. Given a subexpression `E`, the
|
| 50 |
expression `views::single(E)` is expression-equivalent to
|
| 51 |
-
`single_view
|
| 52 |
|
| 53 |
[*Example 1*:
|
| 54 |
|
| 55 |
``` cpp
|
| 56 |
-
|
| 57 |
-
for (int i : s)
|
| 58 |
cout << i; // prints 4
|
| 59 |
```
|
| 60 |
|
| 61 |
— *end example*]
|
| 62 |
|
| 63 |
#### Class template `single_view` <a id="range.single.view">[[range.single.view]]</a>
|
| 64 |
|
| 65 |
``` cpp
|
| 66 |
namespace std::ranges {
|
| 67 |
-
template<
|
| 68 |
requires is_object_v<T>
|
| 69 |
class single_view : public view_interface<single_view<T>> {
|
| 70 |
private:
|
| 71 |
-
|
|
|
|
| 72 |
public:
|
| 73 |
-
single_view() = default;
|
| 74 |
-
constexpr explicit single_view(const T& t);
|
| 75 |
constexpr explicit single_view(T&& t);
|
| 76 |
template<class... Args>
|
| 77 |
requires constructible_from<T, Args...>
|
| 78 |
-
constexpr single_view(in_place_t, Args&&... args);
|
| 79 |
|
| 80 |
constexpr T* begin() noexcept;
|
| 81 |
constexpr const T* begin() const noexcept;
|
| 82 |
constexpr T* end() noexcept;
|
| 83 |
constexpr const T* end() const noexcept;
|
| 84 |
static constexpr size_t size() noexcept;
|
| 85 |
constexpr T* data() noexcept;
|
| 86 |
constexpr const T* data() const noexcept;
|
| 87 |
};
|
|
|
|
|
|
|
|
|
|
| 88 |
}
|
| 89 |
```
|
| 90 |
|
| 91 |
``` cpp
|
| 92 |
-
constexpr explicit single_view(const T& t);
|
| 93 |
```
|
| 94 |
|
| 95 |
*Effects:* Initializes *value\_* with `t`.
|
| 96 |
|
| 97 |
``` cpp
|
|
@@ -100,11 +105,12 @@ constexpr explicit single_view(T&& t);
|
|
| 100 |
|
| 101 |
*Effects:* Initializes *value\_* with `std::move(t)`.
|
| 102 |
|
| 103 |
``` cpp
|
| 104 |
template<class... Args>
|
| 105 |
-
|
|
|
|
| 106 |
```
|
| 107 |
|
| 108 |
*Effects:* Initializes *value\_* as if by
|
| 109 |
*`value_`*`{in_place, std::forward<Args>(args)...}`.
|
| 110 |
|
|
@@ -143,49 +149,50 @@ constexpr const T* data() const noexcept;
|
|
| 143 |
an initial value.
|
| 144 |
|
| 145 |
The name `views::iota` denotes a customization point object
|
| 146 |
[[customization.point.object]]. Given subexpressions `E` and `F`, the
|
| 147 |
expressions `views::iota(E)` and `views::iota(E, F)` are
|
| 148 |
-
expression-equivalent to `iota_view
|
| 149 |
respectively.
|
| 150 |
|
| 151 |
[*Example 1*:
|
| 152 |
|
| 153 |
``` cpp
|
| 154 |
-
for (int i :
|
| 155 |
-
cout << i << ' '; // prints
|
| 156 |
```
|
| 157 |
|
| 158 |
— *end example*]
|
| 159 |
|
| 160 |
#### Class template `iota_view` <a id="range.iota.view">[[range.iota.view]]</a>
|
| 161 |
|
| 162 |
``` cpp
|
| 163 |
namespace std::ranges {
|
| 164 |
template<class I>
|
| 165 |
-
concept decrementable =
|
| 166 |
-
|
| 167 |
template<class I>
|
| 168 |
-
concept advanceable =
|
| 169 |
-
see below;
|
| 170 |
|
| 171 |
template<weakly_incrementable W, semiregular Bound = unreachable_sentinel_t>
|
| 172 |
-
requires weakly-equality-comparable-with<W, Bound> &&
|
| 173 |
class iota_view : public view_interface<iota_view<W, Bound>> {
|
| 174 |
private:
|
| 175 |
// [range.iota.iterator], class iota_view::iterator
|
| 176 |
struct iterator; // exposition only
|
|
|
|
| 177 |
// [range.iota.sentinel], class iota_view::sentinel
|
| 178 |
struct sentinel; // exposition only
|
|
|
|
| 179 |
W value_ = W(); // exposition only
|
| 180 |
Bound bound_ = Bound(); // exposition only
|
|
|
|
| 181 |
public:
|
| 182 |
-
iota_view() = default;
|
| 183 |
constexpr explicit iota_view(W value);
|
| 184 |
-
constexpr iota_view(type_identity_t<W> value,
|
| 185 |
-
|
| 186 |
-
constexpr iota_view(iterator first, sentinel last) : iota_view(*first, last.bound_) {}
|
| 187 |
|
| 188 |
constexpr iterator begin() const;
|
| 189 |
constexpr auto end() const;
|
| 190 |
constexpr iterator end() const requires same_as<W, Bound>;
|
| 191 |
|
|
@@ -213,11 +220,11 @@ Let `IOTA-DIFF-T(W)` be defined as follows:
|
|
| 213 |
|
| 214 |
The exposition-only *decrementable* concept is equivalent to:
|
| 215 |
|
| 216 |
``` cpp
|
| 217 |
template<class I>
|
| 218 |
-
concept decrementable =
|
| 219 |
incrementable<I> && requires(I i) {
|
| 220 |
{ --i } -> same_as<I&>;
|
| 221 |
{ i-- } -> same_as<I>;
|
| 222 |
};
|
| 223 |
```
|
|
@@ -237,11 +244,11 @@ only if
|
|
| 237 |
|
| 238 |
The exposition-only *advanceable* concept is equivalent to:
|
| 239 |
|
| 240 |
``` cpp
|
| 241 |
template<class I>
|
| 242 |
-
concept advanceable =
|
| 243 |
decrementable<I> && totally_ordered<I> &&
|
| 244 |
requires(I i, const I j, const IOTA-DIFF-T(I) n) {
|
| 245 |
{ i += n } -> same_as<I&>;
|
| 246 |
{ i -= n } -> same_as<I&>;
|
| 247 |
I(j + n);
|
|
@@ -275,30 +282,49 @@ value `n` of type `D`. `I` models `advanceable` only if
|
|
| 275 |
``` cpp
|
| 276 |
constexpr explicit iota_view(W value);
|
| 277 |
```
|
| 278 |
|
| 279 |
*Preconditions:* `Bound` denotes `unreachable_sentinel_t` or `Bound()`
|
| 280 |
-
is reachable from `value`.
|
|
|
|
| 281 |
|
| 282 |
*Effects:* Initializes *value\_* with `value`.
|
| 283 |
|
| 284 |
``` cpp
|
| 285 |
-
constexpr iota_view(type_identity_t<W> value, type_identity_t<Bound> bound);
|
| 286 |
```
|
| 287 |
|
| 288 |
*Preconditions:* `Bound` denotes `unreachable_sentinel_t` or `bound` is
|
| 289 |
reachable from `value`. When `W` and `Bound` model
|
| 290 |
`totally_ordered_with`, then `bool(value <= bound)` is `true`.
|
| 291 |
|
| 292 |
*Effects:* Initializes *value\_* with `value` and *bound\_* with
|
| 293 |
`bound`.
|
| 294 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
``` cpp
|
| 296 |
constexpr iterator begin() const;
|
| 297 |
```
|
| 298 |
|
| 299 |
-
*Effects:* Equivalent to: `return iterator{`*`value_`*`};`
|
| 300 |
|
| 301 |
``` cpp
|
| 302 |
constexpr auto end() const;
|
| 303 |
```
|
| 304 |
|
|
@@ -313,11 +339,11 @@ else
|
|
| 313 |
|
| 314 |
``` cpp
|
| 315 |
constexpr iterator end() const requires same_as<W, Bound>;
|
| 316 |
```
|
| 317 |
|
| 318 |
-
*Effects:* Equivalent to: `return iterator{bound_};`
|
| 319 |
|
| 320 |
``` cpp
|
| 321 |
constexpr auto size() const requires see below;
|
| 322 |
```
|
| 323 |
|
|
@@ -332,33 +358,35 @@ if constexpr (is-integer-like<W> && is-integer-like<Bound>)
|
|
| 332 |
: to-unsigned-like(bound_) - to-unsigned-like(value_);
|
| 333 |
else
|
| 334 |
return to-unsigned-like(bound_ - value_);
|
| 335 |
```
|
| 336 |
|
| 337 |
-
*Remarks:* The expression in the *requires-clause* is equivalent to
|
| 338 |
|
| 339 |
``` cpp
|
| 340 |
-
(same_as<W, Bound> && advanceable<W>) || (
|
| 341 |
sized_sentinel_for<Bound, W>
|
| 342 |
```
|
| 343 |
|
| 344 |
#### Class `iota_view::iterator` <a id="range.iota.iterator">[[range.iota.iterator]]</a>
|
| 345 |
|
| 346 |
``` cpp
|
| 347 |
namespace std::ranges {
|
| 348 |
template<weakly_incrementable W, semiregular Bound>
|
| 349 |
-
requires weakly-equality-comparable-with<W, Bound>
|
| 350 |
struct iota_view<W, Bound>::iterator {
|
| 351 |
private:
|
| 352 |
W value_ = W(); // exposition only
|
|
|
|
| 353 |
public:
|
| 354 |
using iterator_concept = see below;
|
| 355 |
-
using iterator_category = input_iterator_tag;
|
|
|
|
| 356 |
using value_type = W;
|
| 357 |
using difference_type = IOTA-DIFF-T(W);
|
| 358 |
|
| 359 |
-
iterator() = default;
|
| 360 |
constexpr explicit iterator(W value);
|
| 361 |
|
| 362 |
constexpr W operator*() const noexcept(is_nothrow_copy_constructible_v<W>);
|
| 363 |
|
| 364 |
constexpr iterator& operator++();
|
|
@@ -572,11 +600,16 @@ friend constexpr auto operator<=>(const iterator& x, const iterator& y)
|
|
| 572 |
``` cpp
|
| 573 |
friend constexpr iterator operator+(iterator i, difference_type n)
|
| 574 |
requires advanceable<W>;
|
| 575 |
```
|
| 576 |
|
| 577 |
-
*Effects:* Equivalent to:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 578 |
|
| 579 |
``` cpp
|
| 580 |
friend constexpr iterator operator+(difference_type n, iterator i)
|
| 581 |
requires advanceable<W>;
|
| 582 |
```
|
|
@@ -586,11 +619,16 @@ friend constexpr iterator operator+(difference_type n, iterator i)
|
|
| 586 |
``` cpp
|
| 587 |
friend constexpr iterator operator-(iterator i, difference_type n)
|
| 588 |
requires advanceable<W>;
|
| 589 |
```
|
| 590 |
|
| 591 |
-
*Effects:* Equivalent to:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 592 |
|
| 593 |
``` cpp
|
| 594 |
friend constexpr difference_type operator-(const iterator& x, const iterator& y)
|
| 595 |
requires advanceable<W>;
|
| 596 |
```
|
|
@@ -614,14 +652,15 @@ if constexpr (is-integer-like<W>) {
|
|
| 614 |
#### Class `iota_view::sentinel` <a id="range.iota.sentinel">[[range.iota.sentinel]]</a>
|
| 615 |
|
| 616 |
``` cpp
|
| 617 |
namespace std::ranges {
|
| 618 |
template<weakly_incrementable W, semiregular Bound>
|
| 619 |
-
requires weakly-equality-comparable-with<W, Bound>
|
| 620 |
struct iota_view<W, Bound>::sentinel {
|
| 621 |
private:
|
| 622 |
Bound bound_ = Bound(); // exposition only
|
|
|
|
| 623 |
public:
|
| 624 |
sentinel() = default;
|
| 625 |
constexpr explicit sentinel(Bound bound);
|
| 626 |
|
| 627 |
friend constexpr bool operator==(const iterator& x, const sentinel& y);
|
|
@@ -658,22 +697,356 @@ friend constexpr iter_difference_t<W> operator-(const sentinel& x, const iterato
|
|
| 658 |
requires sized_sentinel_for<Bound, W>;
|
| 659 |
```
|
| 660 |
|
| 661 |
*Effects:* Equivalent to: `return -(y - x);`
|
| 662 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 663 |
### Istream view <a id="range.istream">[[range.istream]]</a>
|
| 664 |
|
| 665 |
#### Overview <a id="range.istream.overview">[[range.istream.overview]]</a>
|
| 666 |
|
| 667 |
`basic_istream_view` models `input_range` and reads (using `operator>>`)
|
| 668 |
successive elements from its corresponding input stream.
|
| 669 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 670 |
[*Example 1*:
|
| 671 |
|
| 672 |
``` cpp
|
| 673 |
auto ints = istringstream{"0 1 2 3 4"};
|
| 674 |
-
ranges::copy(
|
| 675 |
// prints 0-1-2-3-4-
|
| 676 |
```
|
| 677 |
|
| 678 |
— *end example*]
|
| 679 |
|
|
@@ -685,32 +1058,29 @@ namespace std::ranges {
|
|
| 685 |
concept stream-extractable = // exposition only
|
| 686 |
requires(basic_istream<CharT, Traits>& is, Val& t) {
|
| 687 |
is >> t;
|
| 688 |
};
|
| 689 |
|
| 690 |
-
template<movable Val, class CharT, class Traits>
|
| 691 |
requires default_initializable<Val> &&
|
| 692 |
stream-extractable<Val, CharT, Traits>
|
| 693 |
class basic_istream_view : public view_interface<basic_istream_view<Val, CharT, Traits>> {
|
| 694 |
public:
|
| 695 |
-
basic_istream_view() = default;
|
| 696 |
constexpr explicit basic_istream_view(basic_istream<CharT, Traits>& stream);
|
| 697 |
|
| 698 |
-
constexpr auto begin()
|
| 699 |
-
|
| 700 |
-
if (stream_) {
|
| 701 |
-
*stream_ >> object_;
|
| 702 |
-
}
|
| 703 |
return iterator{*this};
|
| 704 |
}
|
| 705 |
|
| 706 |
constexpr default_sentinel_t end() const noexcept;
|
| 707 |
|
| 708 |
private:
|
|
|
|
| 709 |
struct iterator; // exposition only
|
| 710 |
-
basic_istream<CharT, Traits>* stream_
|
| 711 |
-
Val
|
| 712 |
};
|
| 713 |
}
|
| 714 |
```
|
| 715 |
|
| 716 |
``` cpp
|
|
@@ -723,32 +1093,23 @@ constexpr explicit basic_istream_view(basic_istream<CharT, Traits>& stream);
|
|
| 723 |
constexpr default_sentinel_t end() const noexcept;
|
| 724 |
```
|
| 725 |
|
| 726 |
*Effects:* Equivalent to: `return default_sentinel;`
|
| 727 |
|
| 728 |
-
``
|
| 729 |
-
template<class Val, class CharT, class Traits>
|
| 730 |
-
basic_istream_view<Val, CharT, Traits> istream_view(basic_istream<CharT, Traits>& s);
|
| 731 |
-
```
|
| 732 |
-
|
| 733 |
-
*Effects:* Equivalent to:
|
| 734 |
-
`return basic_istream_view<Val, CharT, Traits>{s};`
|
| 735 |
-
|
| 736 |
-
#### Class template `basic_istream_view::iterator` <a id="range.istream.iterator">[[range.istream.iterator]]</a>
|
| 737 |
|
| 738 |
``` cpp
|
| 739 |
namespace std::ranges {
|
| 740 |
template<movable Val, class CharT, class Traits>
|
| 741 |
requires default_initializable<Val> &&
|
| 742 |
stream-extractable<Val, CharT, Traits>
|
| 743 |
-
class basic_istream_view<Val, CharT, Traits>::iterator {
|
| 744 |
public:
|
| 745 |
using iterator_concept = input_iterator_tag;
|
| 746 |
using difference_type = ptrdiff_t;
|
| 747 |
using value_type = Val;
|
| 748 |
|
| 749 |
-
iterator() = default;
|
| 750 |
constexpr explicit iterator(basic_istream_view& parent) noexcept;
|
| 751 |
|
| 752 |
iterator(const iterator&) = delete;
|
| 753 |
iterator(iterator&&) = default;
|
| 754 |
|
|
@@ -761,11 +1122,11 @@ namespace std::ranges {
|
|
| 761 |
Val& operator*() const;
|
| 762 |
|
| 763 |
friend bool operator==(const iterator& x, default_sentinel_t);
|
| 764 |
|
| 765 |
private:
|
| 766 |
-
basic_istream_view* parent_
|
| 767 |
};
|
| 768 |
}
|
| 769 |
```
|
| 770 |
|
| 771 |
``` cpp
|
|
@@ -776,37 +1137,30 @@ constexpr explicit iterator(basic_istream_view& parent) noexcept;
|
|
| 776 |
|
| 777 |
``` cpp
|
| 778 |
iterator& operator++();
|
| 779 |
```
|
| 780 |
|
| 781 |
-
*Preconditions:* *`parent_`*`->`*`stream_`*` != nullptr` is `true`.
|
| 782 |
-
|
| 783 |
*Effects:* Equivalent to:
|
| 784 |
|
| 785 |
``` cpp
|
| 786 |
-
*parent_->stream_>> parent_->
|
| 787 |
return *this;
|
| 788 |
```
|
| 789 |
|
| 790 |
``` cpp
|
| 791 |
void operator++(int);
|
| 792 |
```
|
| 793 |
|
| 794 |
-
*Preconditions:* *`parent_`*`->`*`stream_`*` != nullptr` is `true`.
|
| 795 |
-
|
| 796 |
*Effects:* Equivalent to `++*this`.
|
| 797 |
|
| 798 |
``` cpp
|
| 799 |
Val& operator*() const;
|
| 800 |
```
|
| 801 |
|
| 802 |
-
*
|
| 803 |
-
|
| 804 |
-
*Effects:* Equivalent to: `return `*`parent_`*`->`*`object_`*`;`
|
| 805 |
|
| 806 |
``` cpp
|
| 807 |
friend bool operator==(const iterator& x, default_sentinel_t);
|
| 808 |
```
|
| 809 |
|
| 810 |
-
*Effects:* Equivalent to:
|
| 811 |
-
`return x.`*`parent_`*` == nullptr || !*x.`*`parent_`*`->`*`stream_`*`;`
|
| 812 |
|
|
|
|
| 1 |
## Range factories <a id="range.factories">[[range.factories]]</a>
|
| 2 |
|
| 3 |
+
### General <a id="range.factories.general">[[range.factories.general]]</a>
|
| 4 |
+
|
| 5 |
+
Subclause [[range.factories]] defines *range factories*, which are
|
| 6 |
+
utilities to create a view.
|
| 7 |
|
| 8 |
Range factories are declared in namespace `std::ranges::views`.
|
| 9 |
|
| 10 |
### Empty view <a id="range.empty">[[range.empty]]</a>
|
| 11 |
|
| 12 |
#### Overview <a id="range.empty.overview">[[range.empty.overview]]</a>
|
| 13 |
|
| 14 |
+
`empty_view` produces a view of no elements of a particular type.
|
| 15 |
|
| 16 |
[*Example 1*:
|
| 17 |
|
| 18 |
``` cpp
|
| 19 |
+
auto e = views::empty<int>;
|
| 20 |
static_assert(ranges::empty(e));
|
| 21 |
static_assert(0 == e.size());
|
| 22 |
```
|
| 23 |
|
| 24 |
— *end example*]
|
|
|
|
| 42 |
|
| 43 |
### Single view <a id="range.single">[[range.single]]</a>
|
| 44 |
|
| 45 |
#### Overview <a id="range.single.overview">[[range.single.overview]]</a>
|
| 46 |
|
| 47 |
+
`single_view` produces a view that contains exactly one element of a
|
| 48 |
specified value.
|
| 49 |
|
| 50 |
The name `views::single` denotes a customization point object
|
| 51 |
[[customization.point.object]]. Given a subexpression `E`, the
|
| 52 |
expression `views::single(E)` is expression-equivalent to
|
| 53 |
+
`single_view<decay_t<decltype((E))>>(E)`.
|
| 54 |
|
| 55 |
[*Example 1*:
|
| 56 |
|
| 57 |
``` cpp
|
| 58 |
+
for (int i : views::single(4))
|
|
|
|
| 59 |
cout << i; // prints 4
|
| 60 |
```
|
| 61 |
|
| 62 |
— *end example*]
|
| 63 |
|
| 64 |
#### Class template `single_view` <a id="range.single.view">[[range.single.view]]</a>
|
| 65 |
|
| 66 |
``` cpp
|
| 67 |
namespace std::ranges {
|
| 68 |
+
template<move_constructible T>
|
| 69 |
requires is_object_v<T>
|
| 70 |
class single_view : public view_interface<single_view<T>> {
|
| 71 |
private:
|
| 72 |
+
movable-box<T> value_; // exposition only{} (see [range.move.wrap])
|
| 73 |
+
|
| 74 |
public:
|
| 75 |
+
single_view() requires default_initializable<T> = default;
|
| 76 |
+
constexpr explicit single_view(const T& t) requires copy_constructible<T>;
|
| 77 |
constexpr explicit single_view(T&& t);
|
| 78 |
template<class... Args>
|
| 79 |
requires constructible_from<T, Args...>
|
| 80 |
+
constexpr explicit single_view(in_place_t, Args&&... args);
|
| 81 |
|
| 82 |
constexpr T* begin() noexcept;
|
| 83 |
constexpr const T* begin() const noexcept;
|
| 84 |
constexpr T* end() noexcept;
|
| 85 |
constexpr const T* end() const noexcept;
|
| 86 |
static constexpr size_t size() noexcept;
|
| 87 |
constexpr T* data() noexcept;
|
| 88 |
constexpr const T* data() const noexcept;
|
| 89 |
};
|
| 90 |
+
|
| 91 |
+
template<class T>
|
| 92 |
+
single_view(T) -> single_view<T>;
|
| 93 |
}
|
| 94 |
```
|
| 95 |
|
| 96 |
``` cpp
|
| 97 |
+
constexpr explicit single_view(const T& t) requires copy_constructible<T>;
|
| 98 |
```
|
| 99 |
|
| 100 |
*Effects:* Initializes *value\_* with `t`.
|
| 101 |
|
| 102 |
``` cpp
|
|
|
|
| 105 |
|
| 106 |
*Effects:* Initializes *value\_* with `std::move(t)`.
|
| 107 |
|
| 108 |
``` cpp
|
| 109 |
template<class... Args>
|
| 110 |
+
requires constructible_from<T, Args...>
|
| 111 |
+
constexpr explicit single_view(in_place_t, Args&&... args);
|
| 112 |
```
|
| 113 |
|
| 114 |
*Effects:* Initializes *value\_* as if by
|
| 115 |
*`value_`*`{in_place, std::forward<Args>(args)...}`.
|
| 116 |
|
|
|
|
| 149 |
an initial value.
|
| 150 |
|
| 151 |
The name `views::iota` denotes a customization point object
|
| 152 |
[[customization.point.object]]. Given subexpressions `E` and `F`, the
|
| 153 |
expressions `views::iota(E)` and `views::iota(E, F)` are
|
| 154 |
+
expression-equivalent to `iota_view(E)` and `iota_view(E, F)`,
|
| 155 |
respectively.
|
| 156 |
|
| 157 |
[*Example 1*:
|
| 158 |
|
| 159 |
``` cpp
|
| 160 |
+
for (int i : views::iota(1, 10))
|
| 161 |
+
cout << i << ' '; // prints 1 2 3 4 5 6 7 8 9
|
| 162 |
```
|
| 163 |
|
| 164 |
— *end example*]
|
| 165 |
|
| 166 |
#### Class template `iota_view` <a id="range.iota.view">[[range.iota.view]]</a>
|
| 167 |
|
| 168 |
``` cpp
|
| 169 |
namespace std::ranges {
|
| 170 |
template<class I>
|
| 171 |
+
concept exposition onlyconceptnc{decrementable} = see belownc; // exposition only
|
| 172 |
+
|
| 173 |
template<class I>
|
| 174 |
+
concept exposition onlyconceptnc{advanceable} = see belownc; // exposition only
|
|
|
|
| 175 |
|
| 176 |
template<weakly_incrementable W, semiregular Bound = unreachable_sentinel_t>
|
| 177 |
+
requires weakly-equality-comparable-with<W, Bound> && copyable<W>
|
| 178 |
class iota_view : public view_interface<iota_view<W, Bound>> {
|
| 179 |
private:
|
| 180 |
// [range.iota.iterator], class iota_view::iterator
|
| 181 |
struct iterator; // exposition only
|
| 182 |
+
|
| 183 |
// [range.iota.sentinel], class iota_view::sentinel
|
| 184 |
struct sentinel; // exposition only
|
| 185 |
+
|
| 186 |
W value_ = W(); // exposition only
|
| 187 |
Bound bound_ = Bound(); // exposition only
|
| 188 |
+
|
| 189 |
public:
|
| 190 |
+
iota_view() requires default_initializable<W> = default;
|
| 191 |
constexpr explicit iota_view(W value);
|
| 192 |
+
constexpr explicit iota_view(type_identity_t<W> value, type_identity_t<Bound> bound);
|
| 193 |
+
constexpr explicit iota_view(iterator first, see below last);
|
|
|
|
| 194 |
|
| 195 |
constexpr iterator begin() const;
|
| 196 |
constexpr auto end() const;
|
| 197 |
constexpr iterator end() const requires same_as<W, Bound>;
|
| 198 |
|
|
|
|
| 220 |
|
| 221 |
The exposition-only *decrementable* concept is equivalent to:
|
| 222 |
|
| 223 |
``` cpp
|
| 224 |
template<class I>
|
| 225 |
+
concept decrementable = // exposition only
|
| 226 |
incrementable<I> && requires(I i) {
|
| 227 |
{ --i } -> same_as<I&>;
|
| 228 |
{ i-- } -> same_as<I>;
|
| 229 |
};
|
| 230 |
```
|
|
|
|
| 244 |
|
| 245 |
The exposition-only *advanceable* concept is equivalent to:
|
| 246 |
|
| 247 |
``` cpp
|
| 248 |
template<class I>
|
| 249 |
+
concept advanceable = // exposition only
|
| 250 |
decrementable<I> && totally_ordered<I> &&
|
| 251 |
requires(I i, const I j, const IOTA-DIFF-T(I) n) {
|
| 252 |
{ i += n } -> same_as<I&>;
|
| 253 |
{ i -= n } -> same_as<I&>;
|
| 254 |
I(j + n);
|
|
|
|
| 282 |
``` cpp
|
| 283 |
constexpr explicit iota_view(W value);
|
| 284 |
```
|
| 285 |
|
| 286 |
*Preconditions:* `Bound` denotes `unreachable_sentinel_t` or `Bound()`
|
| 287 |
+
is reachable from `value`. When `W` and `Bound` model
|
| 288 |
+
`totally_ordered_with`, then `bool(value <= Bound())` is `true`.
|
| 289 |
|
| 290 |
*Effects:* Initializes *value\_* with `value`.
|
| 291 |
|
| 292 |
``` cpp
|
| 293 |
+
constexpr explicit iota_view(type_identity_t<W> value, type_identity_t<Bound> bound);
|
| 294 |
```
|
| 295 |
|
| 296 |
*Preconditions:* `Bound` denotes `unreachable_sentinel_t` or `bound` is
|
| 297 |
reachable from `value`. When `W` and `Bound` model
|
| 298 |
`totally_ordered_with`, then `bool(value <= bound)` is `true`.
|
| 299 |
|
| 300 |
*Effects:* Initializes *value\_* with `value` and *bound\_* with
|
| 301 |
`bound`.
|
| 302 |
|
| 303 |
+
``` cpp
|
| 304 |
+
constexpr explicit iota_view(iterator first, see below last);
|
| 305 |
+
```
|
| 306 |
+
|
| 307 |
+
*Effects:* Equivalent to:
|
| 308 |
+
|
| 309 |
+
- If `same_as<W, Bound>` is `true`,
|
| 310 |
+
`iota_view(first.`*`value_`*`, last.`*`value_`*`)`.
|
| 311 |
+
- Otherwise, if `Bound` denotes `unreachable_sentinel_t`,
|
| 312 |
+
`iota_view(first.`*`value_`*`, last)`.
|
| 313 |
+
- Otherwise, `iota_view(first.`*`value_`*`, last.`*`bound_`*`)`.
|
| 314 |
+
|
| 315 |
+
*Remarks:* The type of `last` is:
|
| 316 |
+
|
| 317 |
+
- If `same_as<W, Bound>` is `true`, *iterator*.
|
| 318 |
+
- Otherwise, if `Bound` denotes `unreachable_sentinel_t`, `Bound`.
|
| 319 |
+
- Otherwise, *sentinel*.
|
| 320 |
+
|
| 321 |
``` cpp
|
| 322 |
constexpr iterator begin() const;
|
| 323 |
```
|
| 324 |
|
| 325 |
+
*Effects:* Equivalent to: `return `*`iterator`*`{`*`value_`*`};`
|
| 326 |
|
| 327 |
``` cpp
|
| 328 |
constexpr auto end() const;
|
| 329 |
```
|
| 330 |
|
|
|
|
| 339 |
|
| 340 |
``` cpp
|
| 341 |
constexpr iterator end() const requires same_as<W, Bound>;
|
| 342 |
```
|
| 343 |
|
| 344 |
+
*Effects:* Equivalent to: `return `*`iterator`*`{`*`bound_`*`};`
|
| 345 |
|
| 346 |
``` cpp
|
| 347 |
constexpr auto size() const requires see below;
|
| 348 |
```
|
| 349 |
|
|
|
|
| 358 |
: to-unsigned-like(bound_) - to-unsigned-like(value_);
|
| 359 |
else
|
| 360 |
return to-unsigned-like(bound_ - value_);
|
| 361 |
```
|
| 362 |
|
| 363 |
+
*Remarks:* The expression in the *requires-clause* is equivalent to:
|
| 364 |
|
| 365 |
``` cpp
|
| 366 |
+
(same_as<W, Bound> && advanceable<W>) || (is-integer-like<W> && is-integer-like<Bound>) ||
|
| 367 |
sized_sentinel_for<Bound, W>
|
| 368 |
```
|
| 369 |
|
| 370 |
#### Class `iota_view::iterator` <a id="range.iota.iterator">[[range.iota.iterator]]</a>
|
| 371 |
|
| 372 |
``` cpp
|
| 373 |
namespace std::ranges {
|
| 374 |
template<weakly_incrementable W, semiregular Bound>
|
| 375 |
+
requires weakly-equality-comparable-with<W, Bound> && copyable<W>
|
| 376 |
struct iota_view<W, Bound>::iterator {
|
| 377 |
private:
|
| 378 |
W value_ = W(); // exposition only
|
| 379 |
+
|
| 380 |
public:
|
| 381 |
using iterator_concept = see below;
|
| 382 |
+
using iterator_category = input_iterator_tag; // present only if W models incrementable and
|
| 383 |
+
// IOTA-DIFF-T(W) is an integral type
|
| 384 |
using value_type = W;
|
| 385 |
using difference_type = IOTA-DIFF-T(W);
|
| 386 |
|
| 387 |
+
iterator() requires default_initializable<W> = default;
|
| 388 |
constexpr explicit iterator(W value);
|
| 389 |
|
| 390 |
constexpr W operator*() const noexcept(is_nothrow_copy_constructible_v<W>);
|
| 391 |
|
| 392 |
constexpr iterator& operator++();
|
|
|
|
| 600 |
``` cpp
|
| 601 |
friend constexpr iterator operator+(iterator i, difference_type n)
|
| 602 |
requires advanceable<W>;
|
| 603 |
```
|
| 604 |
|
| 605 |
+
*Effects:* Equivalent to:
|
| 606 |
+
|
| 607 |
+
``` cpp
|
| 608 |
+
i += n;
|
| 609 |
+
return i;
|
| 610 |
+
```
|
| 611 |
|
| 612 |
``` cpp
|
| 613 |
friend constexpr iterator operator+(difference_type n, iterator i)
|
| 614 |
requires advanceable<W>;
|
| 615 |
```
|
|
|
|
| 619 |
``` cpp
|
| 620 |
friend constexpr iterator operator-(iterator i, difference_type n)
|
| 621 |
requires advanceable<W>;
|
| 622 |
```
|
| 623 |
|
| 624 |
+
*Effects:* Equivalent to:
|
| 625 |
+
|
| 626 |
+
``` cpp
|
| 627 |
+
i -= n;
|
| 628 |
+
return i;
|
| 629 |
+
```
|
| 630 |
|
| 631 |
``` cpp
|
| 632 |
friend constexpr difference_type operator-(const iterator& x, const iterator& y)
|
| 633 |
requires advanceable<W>;
|
| 634 |
```
|
|
|
|
| 652 |
#### Class `iota_view::sentinel` <a id="range.iota.sentinel">[[range.iota.sentinel]]</a>
|
| 653 |
|
| 654 |
``` cpp
|
| 655 |
namespace std::ranges {
|
| 656 |
template<weakly_incrementable W, semiregular Bound>
|
| 657 |
+
requires weakly-equality-comparable-with<W, Bound> && copyable<W>
|
| 658 |
struct iota_view<W, Bound>::sentinel {
|
| 659 |
private:
|
| 660 |
Bound bound_ = Bound(); // exposition only
|
| 661 |
+
|
| 662 |
public:
|
| 663 |
sentinel() = default;
|
| 664 |
constexpr explicit sentinel(Bound bound);
|
| 665 |
|
| 666 |
friend constexpr bool operator==(const iterator& x, const sentinel& y);
|
|
|
|
| 697 |
requires sized_sentinel_for<Bound, W>;
|
| 698 |
```
|
| 699 |
|
| 700 |
*Effects:* Equivalent to: `return -(y - x);`
|
| 701 |
|
| 702 |
+
### Repeat view <a id="range.repeat">[[range.repeat]]</a>
|
| 703 |
+
|
| 704 |
+
#### Overview <a id="range.repeat.overview">[[range.repeat.overview]]</a>
|
| 705 |
+
|
| 706 |
+
`repeat_view` generates a sequence of elements by repeatedly producing
|
| 707 |
+
the same value.
|
| 708 |
+
|
| 709 |
+
The name `views::repeat` denotes a customization point object
|
| 710 |
+
[[customization.point.object]]. Given subexpressions `E` and `F`, the
|
| 711 |
+
expressions `views::repeat(E)` and `views::repeat(E, F)` are
|
| 712 |
+
expression-equivalent to `repeat_view(E)` and `repeat_view(E, F)`,
|
| 713 |
+
respectively.
|
| 714 |
+
|
| 715 |
+
[*Example 1*:
|
| 716 |
+
|
| 717 |
+
``` cpp
|
| 718 |
+
for (int i : views::repeat(17, 4))
|
| 719 |
+
cout << i << ' ';
|
| 720 |
+
// prints 17 17 17 17
|
| 721 |
+
```
|
| 722 |
+
|
| 723 |
+
— *end example*]
|
| 724 |
+
|
| 725 |
+
#### Class template `repeat_view` <a id="range.repeat.view">[[range.repeat.view]]</a>
|
| 726 |
+
|
| 727 |
+
``` cpp
|
| 728 |
+
namespace std::ranges {
|
| 729 |
+
template<class T>
|
| 730 |
+
concept integer-like-with-usable-difference-type = // exposition only
|
| 731 |
+
is-signed-integer-like<T> || (is-integer-like<T> && weakly_incrementable<T>);
|
| 732 |
+
|
| 733 |
+
template<move_constructible T, semiregular Bound = unreachable_sentinel_t>
|
| 734 |
+
requires (is_object_v<T> && same_as<T, remove_cv_t<T>> &&
|
| 735 |
+
(integer-like-with-usable-difference-type<Bound> ||
|
| 736 |
+
same_as<Bound, unreachable_sentinel_t>))
|
| 737 |
+
class repeat_view : public view_interface<repeat_view<T, Bound>> {
|
| 738 |
+
private:
|
| 739 |
+
// [range.repeat.iterator], class repeat_view::iterator
|
| 740 |
+
struct iterator; // exposition only
|
| 741 |
+
|
| 742 |
+
movable-box<T> value_; // exposition only, see [range.move.wrap]
|
| 743 |
+
Bound bound_ = Bound(); // exposition only
|
| 744 |
+
|
| 745 |
+
public:
|
| 746 |
+
repeat_view() requires default_initializable<T> = default;
|
| 747 |
+
|
| 748 |
+
constexpr explicit repeat_view(const T& value, Bound bound = Bound())
|
| 749 |
+
requires copy_constructible<T>;
|
| 750 |
+
constexpr explicit repeat_view(T&& value, Bound bound = Bound());
|
| 751 |
+
template<class... TArgs, class... BoundArgs>
|
| 752 |
+
requires constructible_from<T, TArgs...> &&
|
| 753 |
+
constructible_from<Bound, BoundArgs...>
|
| 754 |
+
constexpr explicit repeat_view(piecewise_construct_t,
|
| 755 |
+
tuple<TArgs...> value_args, tuple<BoundArgs...> bound_args = tuple<>{});
|
| 756 |
+
|
| 757 |
+
constexpr iterator begin() const;
|
| 758 |
+
constexpr iterator end() const requires (!same_as<Bound, unreachable_sentinel_t>);
|
| 759 |
+
constexpr unreachable_sentinel_t end() const noexcept;
|
| 760 |
+
|
| 761 |
+
constexpr auto size() const requires (!same_as<Bound, unreachable_sentinel_t>);
|
| 762 |
+
};
|
| 763 |
+
|
| 764 |
+
template<class T, class Bound>
|
| 765 |
+
repeat_view(T, Bound) -> repeat_view<T, Bound>;
|
| 766 |
+
}
|
| 767 |
+
```
|
| 768 |
+
|
| 769 |
+
``` cpp
|
| 770 |
+
constexpr explicit repeat_view(const T& value, Bound bound = Bound())
|
| 771 |
+
requires copy_constructible<T>;
|
| 772 |
+
```
|
| 773 |
+
|
| 774 |
+
*Preconditions:* If `Bound` is not `unreachable_sentinel_t`,
|
| 775 |
+
`bound` ≥ 0.
|
| 776 |
+
|
| 777 |
+
*Effects:* Initializes *value\_* with `value` and *bound\_* with
|
| 778 |
+
`bound`.
|
| 779 |
+
|
| 780 |
+
``` cpp
|
| 781 |
+
constexpr explicit repeat_view(T&& value, Bound bound = Bound());
|
| 782 |
+
```
|
| 783 |
+
|
| 784 |
+
*Preconditions:* If `Bound` is not `unreachable_sentinel_t`,
|
| 785 |
+
`bound` ≥ 0.
|
| 786 |
+
|
| 787 |
+
*Effects:* Initializes *value\_* with `std::move(value)` and *bound\_*
|
| 788 |
+
with `bound`.
|
| 789 |
+
|
| 790 |
+
``` cpp
|
| 791 |
+
template<class... TArgs, class... BoundArgs>
|
| 792 |
+
requires constructible_from<T, TArgs...> &&
|
| 793 |
+
constructible_from<Bound, BoundArgs...>
|
| 794 |
+
constexpr explicit repeat_view(piecewise_construct_t,
|
| 795 |
+
tuple<TArgs...> value_args, tuple<BoundArgs...> bound_args = tuple<>{});
|
| 796 |
+
```
|
| 797 |
+
|
| 798 |
+
*Effects:* Initializes *value\_* with
|
| 799 |
+
`make_from_tuple<T>(std::move(value_args))` and initializes *bound\_*
|
| 800 |
+
with `make_from_tuple<Bound>(std::move(bound_args))`. The behavior is
|
| 801 |
+
undefined if `Bound` is not `unreachable_sentinel_t` and *bound\_* is
|
| 802 |
+
negative.
|
| 803 |
+
|
| 804 |
+
``` cpp
|
| 805 |
+
constexpr iterator begin() const;
|
| 806 |
+
```
|
| 807 |
+
|
| 808 |
+
*Effects:* Equivalent to:
|
| 809 |
+
`return `*`iterator`*`(addressof(*`*`value_`*`));`
|
| 810 |
+
|
| 811 |
+
``` cpp
|
| 812 |
+
constexpr iterator end() const requires (!same_as<Bound, unreachable_sentinel_t>);
|
| 813 |
+
```
|
| 814 |
+
|
| 815 |
+
*Effects:* Equivalent to:
|
| 816 |
+
`return `*`iterator`*`(addressof(*`*`value_`*`), `*`bound_`*`);`
|
| 817 |
+
|
| 818 |
+
``` cpp
|
| 819 |
+
constexpr unreachable_sentinel_t end() const noexcept;
|
| 820 |
+
```
|
| 821 |
+
|
| 822 |
+
*Effects:* Equivalent to: `return unreachable_sentinel;`
|
| 823 |
+
|
| 824 |
+
``` cpp
|
| 825 |
+
constexpr auto size() const requires (!same_as<Bound, unreachable_sentinel_t>);
|
| 826 |
+
```
|
| 827 |
+
|
| 828 |
+
*Effects:* Equivalent to: `return `*`to-unsigned-like`*`(`*`bound_`*`);`
|
| 829 |
+
|
| 830 |
+
#### Class `repeat_view::iterator` <a id="range.repeat.iterator">[[range.repeat.iterator]]</a>
|
| 831 |
+
|
| 832 |
+
``` cpp
|
| 833 |
+
namespace std::ranges {
|
| 834 |
+
template<move_constructible T, semiregular Bound>
|
| 835 |
+
requires (is_object_v<T> && same_as<T, remove_cv_t<T>> &&
|
| 836 |
+
(integer-like-with-usable-difference-type<Bound> ||
|
| 837 |
+
same_as<Bound, unreachable_sentinel_t>))
|
| 838 |
+
class repeat_view<T, Bound>::iterator {
|
| 839 |
+
private:
|
| 840 |
+
using index-type = // exposition only
|
| 841 |
+
conditional_t<same_as<Bound, unreachable_sentinel_t>, ptrdiff_t, Bound>;
|
| 842 |
+
const T* value_ = nullptr; // exposition only
|
| 843 |
+
index-type current_ = index-type(); // exposition only
|
| 844 |
+
|
| 845 |
+
constexpr explicit iterator(const T* value, index-type b = index-type()); // exposition only
|
| 846 |
+
|
| 847 |
+
public:
|
| 848 |
+
using iterator_concept = random_access_iterator_tag;
|
| 849 |
+
using iterator_category = random_access_iterator_tag;
|
| 850 |
+
using value_type = T;
|
| 851 |
+
using difference_type = see below;
|
| 852 |
+
|
| 853 |
+
iterator() = default;
|
| 854 |
+
|
| 855 |
+
constexpr const T& operator*() const noexcept;
|
| 856 |
+
|
| 857 |
+
constexpr iterator& operator++();
|
| 858 |
+
constexpr iterator operator++(int);
|
| 859 |
+
|
| 860 |
+
constexpr iterator& operator--();
|
| 861 |
+
constexpr iterator operator--(int);
|
| 862 |
+
|
| 863 |
+
constexpr iterator& operator+=(difference_type n);
|
| 864 |
+
constexpr iterator& operator-=(difference_type n);
|
| 865 |
+
constexpr const T& operator[](difference_type n) const noexcept;
|
| 866 |
+
|
| 867 |
+
friend constexpr bool operator==(const iterator& x, const iterator& y);
|
| 868 |
+
friend constexpr auto operator<=>(const iterator& x, const iterator& y);
|
| 869 |
+
|
| 870 |
+
friend constexpr iterator operator+(iterator i, difference_type n);
|
| 871 |
+
friend constexpr iterator operator+(difference_type n, iterator i);
|
| 872 |
+
|
| 873 |
+
friend constexpr iterator operator-(iterator i, difference_type n);
|
| 874 |
+
friend constexpr difference_type operator-(const iterator& x, const iterator& y);
|
| 875 |
+
};
|
| 876 |
+
}
|
| 877 |
+
```
|
| 878 |
+
|
| 879 |
+
If `is-signed-integer-like<index-type>` is `true`, the member
|
| 880 |
+
*typedef-name* `difference_type` denotes *`index-type`*. Otherwise, it
|
| 881 |
+
denotes `IOTA-DIFF-T(index-type)` [[range.iota.view]].
|
| 882 |
+
|
| 883 |
+
``` cpp
|
| 884 |
+
constexpr explicit iterator(const T* value, index-type b = index-type());
|
| 885 |
+
```
|
| 886 |
+
|
| 887 |
+
*Preconditions:* If `Bound` is not `unreachable_sentinel_t`, `b` ≥ 0.
|
| 888 |
+
|
| 889 |
+
*Effects:* Initializes *value\_* with `value` and *current\_* with `b`.
|
| 890 |
+
|
| 891 |
+
``` cpp
|
| 892 |
+
constexpr const T& operator*() const noexcept;
|
| 893 |
+
```
|
| 894 |
+
|
| 895 |
+
*Effects:* Equivalent to: `return *`*`value_`*`;`
|
| 896 |
+
|
| 897 |
+
``` cpp
|
| 898 |
+
constexpr iterator& operator++();
|
| 899 |
+
```
|
| 900 |
+
|
| 901 |
+
*Effects:* Equivalent to:
|
| 902 |
+
|
| 903 |
+
``` cpp
|
| 904 |
+
++current_;
|
| 905 |
+
return *this;
|
| 906 |
+
```
|
| 907 |
+
|
| 908 |
+
``` cpp
|
| 909 |
+
constexpr iterator operator++(int);
|
| 910 |
+
```
|
| 911 |
+
|
| 912 |
+
*Effects:* Equivalent to:
|
| 913 |
+
|
| 914 |
+
``` cpp
|
| 915 |
+
auto tmp = *this;
|
| 916 |
+
++*this;
|
| 917 |
+
return tmp;
|
| 918 |
+
```
|
| 919 |
+
|
| 920 |
+
``` cpp
|
| 921 |
+
constexpr iterator& operator--();
|
| 922 |
+
```
|
| 923 |
+
|
| 924 |
+
*Preconditions:* If `Bound` is not `unreachable_sentinel_t`,
|
| 925 |
+
current_ > 0.
|
| 926 |
+
|
| 927 |
+
*Effects:* Equivalent to:
|
| 928 |
+
|
| 929 |
+
``` cpp
|
| 930 |
+
--current_;
|
| 931 |
+
return *this;
|
| 932 |
+
```
|
| 933 |
+
|
| 934 |
+
``` cpp
|
| 935 |
+
constexpr iterator operator--(int);
|
| 936 |
+
```
|
| 937 |
+
|
| 938 |
+
*Effects:* Equivalent to:
|
| 939 |
+
|
| 940 |
+
``` cpp
|
| 941 |
+
auto tmp = *this;
|
| 942 |
+
--*this;
|
| 943 |
+
return tmp;
|
| 944 |
+
```
|
| 945 |
+
|
| 946 |
+
``` cpp
|
| 947 |
+
constexpr iterator& operator+=(difference_type n);
|
| 948 |
+
```
|
| 949 |
+
|
| 950 |
+
*Preconditions:* If `Bound` is not `unreachable_sentinel_t`,
|
| 951 |
+
current_ + `n` ≥ 0.
|
| 952 |
+
|
| 953 |
+
*Effects:* Equivalent to:
|
| 954 |
+
|
| 955 |
+
``` cpp
|
| 956 |
+
current_ += n;
|
| 957 |
+
return *this;
|
| 958 |
+
```
|
| 959 |
+
|
| 960 |
+
``` cpp
|
| 961 |
+
constexpr iterator& operator-=(difference_type n);
|
| 962 |
+
```
|
| 963 |
+
|
| 964 |
+
*Preconditions:* If `Bound` is not `unreachable_sentinel_t`,
|
| 965 |
+
current_ - `n` ≥ 0.
|
| 966 |
+
|
| 967 |
+
*Effects:* Equivalent to:
|
| 968 |
+
|
| 969 |
+
``` cpp
|
| 970 |
+
current_ -= n;
|
| 971 |
+
return *this;
|
| 972 |
+
```
|
| 973 |
+
|
| 974 |
+
``` cpp
|
| 975 |
+
constexpr const T& operator[](difference_type n) const noexcept;
|
| 976 |
+
```
|
| 977 |
+
|
| 978 |
+
*Effects:* Equivalent to: `return *(*this + n);`
|
| 979 |
+
|
| 980 |
+
``` cpp
|
| 981 |
+
friend constexpr bool operator==(const iterator& x, const iterator& y);
|
| 982 |
+
```
|
| 983 |
+
|
| 984 |
+
*Effects:* Equivalent to: `return x.`*`current_`*` == y.`*`current_`*`;`
|
| 985 |
+
|
| 986 |
+
``` cpp
|
| 987 |
+
friend constexpr auto operator<=>(const iterator& x, const iterator& y);
|
| 988 |
+
```
|
| 989 |
+
|
| 990 |
+
*Effects:* Equivalent to:
|
| 991 |
+
`return x.`*`current_`*` <=> y.`*`current_`*`;`
|
| 992 |
+
|
| 993 |
+
``` cpp
|
| 994 |
+
friend constexpr iterator operator+(iterator i, difference_type n);
|
| 995 |
+
friend constexpr iterator operator+(difference_type n, iterator i);
|
| 996 |
+
```
|
| 997 |
+
|
| 998 |
+
*Effects:* Equivalent to:
|
| 999 |
+
|
| 1000 |
+
``` cpp
|
| 1001 |
+
i += n;
|
| 1002 |
+
return i;
|
| 1003 |
+
```
|
| 1004 |
+
|
| 1005 |
+
``` cpp
|
| 1006 |
+
friend constexpr iterator operator-(iterator i, difference_type n);
|
| 1007 |
+
```
|
| 1008 |
+
|
| 1009 |
+
*Effects:* Equivalent to:
|
| 1010 |
+
|
| 1011 |
+
``` cpp
|
| 1012 |
+
i -= n;
|
| 1013 |
+
return i;
|
| 1014 |
+
```
|
| 1015 |
+
|
| 1016 |
+
``` cpp
|
| 1017 |
+
friend constexpr difference_type operator-(const iterator& x, const iterator& y);
|
| 1018 |
+
```
|
| 1019 |
+
|
| 1020 |
+
*Effects:* Equivalent to:
|
| 1021 |
+
|
| 1022 |
+
``` cpp
|
| 1023 |
+
return static_cast<difference_type>(x.current_) - static_cast<difference_type>(y.current_);
|
| 1024 |
+
```
|
| 1025 |
+
|
| 1026 |
### Istream view <a id="range.istream">[[range.istream]]</a>
|
| 1027 |
|
| 1028 |
#### Overview <a id="range.istream.overview">[[range.istream.overview]]</a>
|
| 1029 |
|
| 1030 |
`basic_istream_view` models `input_range` and reads (using `operator>>`)
|
| 1031 |
successive elements from its corresponding input stream.
|
| 1032 |
|
| 1033 |
+
The name `views::istream<T>` denotes a customization point object
|
| 1034 |
+
[[customization.point.object]]. Given a type `T` and a subexpression `E`
|
| 1035 |
+
of type `U`, if `U` models
|
| 1036 |
+
`derived_from<basic_istream<typename U::char_type,
|
| 1037 |
+
typename U::traits_type>>`, then the expression `views::istream<T>(E)`
|
| 1038 |
+
is expression-equivalent to
|
| 1039 |
+
`basic_istream_view<T, typename U::char_type,
|
| 1040 |
+
typename U::traits_type>(E)`; otherwise, `views::istream<T>(E)` is
|
| 1041 |
+
ill-formed.
|
| 1042 |
+
|
| 1043 |
[*Example 1*:
|
| 1044 |
|
| 1045 |
``` cpp
|
| 1046 |
auto ints = istringstream{"0 1 2 3 4"};
|
| 1047 |
+
ranges::copy(views::istream<int>(ints), ostream_iterator<int>{cout, "-"});
|
| 1048 |
// prints 0-1-2-3-4-
|
| 1049 |
```
|
| 1050 |
|
| 1051 |
— *end example*]
|
| 1052 |
|
|
|
|
| 1058 |
concept stream-extractable = // exposition only
|
| 1059 |
requires(basic_istream<CharT, Traits>& is, Val& t) {
|
| 1060 |
is >> t;
|
| 1061 |
};
|
| 1062 |
|
| 1063 |
+
template<movable Val, class CharT, class Traits = char_traits<CharT>>
|
| 1064 |
requires default_initializable<Val> &&
|
| 1065 |
stream-extractable<Val, CharT, Traits>
|
| 1066 |
class basic_istream_view : public view_interface<basic_istream_view<Val, CharT, Traits>> {
|
| 1067 |
public:
|
|
|
|
| 1068 |
constexpr explicit basic_istream_view(basic_istream<CharT, Traits>& stream);
|
| 1069 |
|
| 1070 |
+
constexpr auto begin() {
|
| 1071 |
+
*stream_ >> value_;
|
|
|
|
|
|
|
|
|
|
| 1072 |
return iterator{*this};
|
| 1073 |
}
|
| 1074 |
|
| 1075 |
constexpr default_sentinel_t end() const noexcept;
|
| 1076 |
|
| 1077 |
private:
|
| 1078 |
+
// [range.istream.iterator], class basic_istream_view::iterator
|
| 1079 |
struct iterator; // exposition only
|
| 1080 |
+
basic_istream<CharT, Traits>* stream_; // exposition only
|
| 1081 |
+
Val value_ = Val(); // exposition only
|
| 1082 |
};
|
| 1083 |
}
|
| 1084 |
```
|
| 1085 |
|
| 1086 |
``` cpp
|
|
|
|
| 1093 |
constexpr default_sentinel_t end() const noexcept;
|
| 1094 |
```
|
| 1095 |
|
| 1096 |
*Effects:* Equivalent to: `return default_sentinel;`
|
| 1097 |
|
| 1098 |
+
#### Class `basic_istream_view::iterator` <a id="range.istream.iterator">[[range.istream.iterator]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1099 |
|
| 1100 |
``` cpp
|
| 1101 |
namespace std::ranges {
|
| 1102 |
template<movable Val, class CharT, class Traits>
|
| 1103 |
requires default_initializable<Val> &&
|
| 1104 |
stream-extractable<Val, CharT, Traits>
|
| 1105 |
+
class basic_istream_view<Val, CharT, Traits>::iterator {
|
| 1106 |
public:
|
| 1107 |
using iterator_concept = input_iterator_tag;
|
| 1108 |
using difference_type = ptrdiff_t;
|
| 1109 |
using value_type = Val;
|
| 1110 |
|
|
|
|
| 1111 |
constexpr explicit iterator(basic_istream_view& parent) noexcept;
|
| 1112 |
|
| 1113 |
iterator(const iterator&) = delete;
|
| 1114 |
iterator(iterator&&) = default;
|
| 1115 |
|
|
|
|
| 1122 |
Val& operator*() const;
|
| 1123 |
|
| 1124 |
friend bool operator==(const iterator& x, default_sentinel_t);
|
| 1125 |
|
| 1126 |
private:
|
| 1127 |
+
basic_istream_view* parent_; // exposition only
|
| 1128 |
};
|
| 1129 |
}
|
| 1130 |
```
|
| 1131 |
|
| 1132 |
``` cpp
|
|
|
|
| 1137 |
|
| 1138 |
``` cpp
|
| 1139 |
iterator& operator++();
|
| 1140 |
```
|
| 1141 |
|
|
|
|
|
|
|
| 1142 |
*Effects:* Equivalent to:
|
| 1143 |
|
| 1144 |
``` cpp
|
| 1145 |
+
*parent_->stream_ >> parent_->value_;
|
| 1146 |
return *this;
|
| 1147 |
```
|
| 1148 |
|
| 1149 |
``` cpp
|
| 1150 |
void operator++(int);
|
| 1151 |
```
|
| 1152 |
|
|
|
|
|
|
|
| 1153 |
*Effects:* Equivalent to `++*this`.
|
| 1154 |
|
| 1155 |
``` cpp
|
| 1156 |
Val& operator*() const;
|
| 1157 |
```
|
| 1158 |
|
| 1159 |
+
*Effects:* Equivalent to: `return `*`parent_`*`->`*`value_`*`;`
|
|
|
|
|
|
|
| 1160 |
|
| 1161 |
``` cpp
|
| 1162 |
friend bool operator==(const iterator& x, default_sentinel_t);
|
| 1163 |
```
|
| 1164 |
|
| 1165 |
+
*Effects:* Equivalent to: `return !*x.`*`parent_`*`->`*`stream_`*`;`
|
|
|
|
| 1166 |
|