From Jason Turner

[range.subrange.general]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpawxz4bde/{from.md → to.md} +98 -0
tmp/tmpawxz4bde/{from.md → to.md} RENAMED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### General <a id="range.subrange.general">[[range.subrange.general]]</a>
2
+
3
+ The `subrange` class template combines together an iterator and a
4
+ sentinel into a single object that models the `view` concept.
5
+ Additionally, it models the `sized_range` concept when the final
6
+ template parameter is `subrange_kind::sized`.
7
+
8
+ ``` cpp
9
+ namespace std::ranges {
10
+ template<class From, class To>
11
+ concept uses-nonqualification-pointer-conversion = // exposition only
12
+ is_pointer_v<From> && is_pointer_v<To> &&
13
+ !convertible_to<remove_pointer_t<From>(*)[], remove_pointer_t<To>(*)[]>;
14
+
15
+ template<class From, class To>
16
+ concept convertible-to-non-slicing = // exposition only
17
+ convertible_to<From, To> &&
18
+ !uses-nonqualification-pointer-conversion<decay_t<From>, decay_t<To>>;
19
+
20
+ template<class T, class U, class V>
21
+ concept pair-like-convertible-from = // exposition only
22
+ !range<T> && !is_reference_v<T> && pair-like<T> &&
23
+ constructible_from<T, U, V> &&
24
+ convertible-to-non-slicing<U, tuple_element_t<0, T>> &&
25
+ convertible_to<V, tuple_element_t<1, T>>;
26
+
27
+ template<input_or_output_iterator I, sentinel_for<I> S = I, subrange_kind K =
28
+ sized_sentinel_for<S, I> ? subrange_kind::sized : subrange_kind::unsized>
29
+ requires (K == subrange_kind::sized || !sized_sentinel_for<S, I>)
30
+ class subrange : public view_interface<subrange<I, S, K>> {
31
+ private:
32
+ static constexpr bool StoreSize = // exposition only
33
+ K == subrange_kind::sized && !sized_sentinel_for<S, I>;
34
+ I begin_ = I(); // exposition only
35
+ S end_ = S(); // exposition only
36
+ make-unsigned-like-t<iter_difference_t<I>> size_ = 0; // exposition only; present only
37
+ // if StoreSize is true
38
+ public:
39
+ subrange() requires default_initializable<I> = default;
40
+
41
+ constexpr subrange(convertible-to-non-slicing<I> auto i, S s) requires (!StoreSize);
42
+
43
+ constexpr subrange(convertible-to-non-slicing<I> auto i, S s,
44
+ make-unsigned-like-t<iter_difference_t<I>> n)
45
+ requires (K == subrange_kind::sized);
46
+
47
+ template<different-from<subrange> R>
48
+ requires borrowed_range<R> &&
49
+ convertible-to-non-slicing<iterator_t<R>, I> &&
50
+ convertible_to<sentinel_t<R>, S>
51
+ constexpr subrange(R&& r) requires (!StoreSize || sized_range<R>);
52
+
53
+ template<borrowed_range R>
54
+ requires convertible-to-non-slicing<iterator_t<R>, I> &&
55
+ convertible_to<sentinel_t<R>, S>
56
+ constexpr subrange(R&& r, make-unsigned-like-t<iter_difference_t<I>> n)
57
+ requires (K == subrange_kind::sized)
58
+ : subrange{ranges::begin(r), ranges::end(r), n} {}
59
+
60
+ template<different-from<subrange> PairLike>
61
+ requires pair-like-convertible-from<PairLike, const I&, const S&>
62
+ constexpr operator PairLike() const;
63
+
64
+ constexpr I begin() const requires copyable<I>;
65
+ [[nodiscard]] constexpr I begin() requires (!copyable<I>);
66
+ constexpr S end() const;
67
+
68
+ constexpr bool empty() const;
69
+ constexpr make-unsigned-like-t<iter_difference_t<I>> size() const
70
+ requires (K == subrange_kind::sized);
71
+
72
+ [[nodiscard]] constexpr subrange next(iter_difference_t<I> n = 1) const &
73
+ requires forward_iterator<I>;
74
+ [[nodiscard]] constexpr subrange next(iter_difference_t<I> n = 1) &&;
75
+ [[nodiscard]] constexpr subrange prev(iter_difference_t<I> n = 1) const
76
+ requires bidirectional_iterator<I>;
77
+ constexpr subrange& advance(iter_difference_t<I> n);
78
+ };
79
+
80
+ template<input_or_output_iterator I, sentinel_for<I> S>
81
+ subrange(I, S) -> subrange<I, S>;
82
+
83
+ template<input_or_output_iterator I, sentinel_for<I> S>
84
+ subrange(I, S, make-unsigned-like-t<iter_difference_t<I>>) ->
85
+ subrange<I, S, subrange_kind::sized>;
86
+
87
+ template<borrowed_range R>
88
+ subrange(R&&) ->
89
+ subrange<iterator_t<R>, sentinel_t<R>,
90
+ (sized_range<R> || sized_sentinel_for<sentinel_t<R>, iterator_t<R>>)
91
+ ? subrange_kind::sized : subrange_kind::unsized>;
92
+
93
+ template<borrowed_range R>
94
+ subrange(R&&, make-unsigned-like-t<range_difference_t<R>>) ->
95
+ subrange<iterator_t<R>, sentinel_t<R>, subrange_kind::sized>;
96
+ }
97
+ ```
98
+