From Jason Turner

[range.cartesian.view]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpxmelifpk/{from.md → to.md} +164 -0
tmp/tmpxmelifpk/{from.md → to.md} RENAMED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### Class template `cartesian_product_view` <a id="range.cartesian.view">[[range.cartesian.view]]</a>
2
+
3
+ ``` cpp
4
+ namespace std::ranges {
5
+ template<bool Const, class First, class... Vs>
6
+ concept cartesian-product-is-random-access = // exposition only
7
+ (random_access_range<maybe-const<Const, First>> && ... &&
8
+ (random_access_range<maybe-const<Const, Vs>>
9
+ && sized_range<maybe-const<Const, Vs>>));
10
+
11
+ template<class R>
12
+ concept cartesian-product-common-arg = // exposition only
13
+ common_range<R> || (sized_range<R> && random_access_range<R>);
14
+
15
+ template<bool Const, class First, class... Vs>
16
+ concept cartesian-product-is-bidirectional = // exposition only
17
+ (bidirectional_range<maybe-const<Const, First>> && ... &&
18
+ (bidirectional_range<maybe-const<Const, Vs>>
19
+ && cartesian-product-common-arg<maybe-const<Const, Vs>>));
20
+
21
+ template<class First, class... Vs>
22
+ concept cartesian-product-is-common = // exposition only
23
+ cartesian-product-common-arg<First>;
24
+
25
+ template<class... Vs>
26
+ concept cartesian-product-is-sized = // exposition only
27
+ (sized_range<Vs> && ...);
28
+
29
+ template<bool Const, template<class> class FirstSent, class First, class... Vs>
30
+ concept cartesian-is-sized-sentinel = // exposition only
31
+ (sized_sentinel_for<FirstSent<maybe-const<Const, First>>,
32
+ iterator_t<maybe-const<Const, First>>> && ...
33
+ && (sized_range<maybe-const<Const, Vs>>
34
+ && sized_sentinel_for<iterator_t<maybe-const<Const, Vs>>,
35
+ iterator_t<maybe-const<Const, Vs>>>));
36
+
37
+ template<cartesian-product-common-arg R>
38
+ constexpr auto cartesian-common-arg-end(R& r) { // exposition only
39
+ if constexpr (common_range<R>) {
40
+ return ranges::end(r);
41
+ } else {
42
+ return ranges::begin(r) + ranges::distance(r);
43
+ }
44
+ }
45
+
46
+ template<input_range First, forward_range... Vs>
47
+ requires (view<First> && ... && view<Vs>)
48
+ class cartesian_product_view : public view_interface<cartesian_product_view<First, Vs...>> {
49
+ private:
50
+ tuple<First, Vs...> bases_; // exposition only
51
+ // [range.cartesian.iterator], class template cartesian_product_view::iterator
52
+ template<bool Const> class iterator; // exposition only
53
+
54
+ public:
55
+ constexpr cartesian_product_view() = default;
56
+ constexpr explicit cartesian_product_view(First first_base, Vs... bases);
57
+
58
+ constexpr iterator<false> begin()
59
+ requires (!simple-view<First> || ... || !simple-view<Vs>);
60
+ constexpr iterator<true> begin() const
61
+ requires (range<const First> && ... && range<const Vs>);
62
+
63
+ constexpr iterator<false> end()
64
+ requires ((!simple-view<First> || ... || !simple-view<Vs>) &&
65
+ cartesian-product-is-common<First, Vs...>);
66
+ constexpr iterator<true> end() const
67
+ requires cartesian-product-is-common<const First, const Vs...>;
68
+ constexpr default_sentinel_t end() const noexcept;
69
+
70
+ constexpr see below size()
71
+ requires cartesian-product-is-sized<First, Vs...>;
72
+ constexpr see below size() const
73
+ requires cartesian-product-is-sized<const First, const Vs...>;
74
+ };
75
+
76
+ template<class... Vs>
77
+ cartesian_product_view(Vs&&...) -> cartesian_product_view<views::all_t<Vs>...>;
78
+ }
79
+ ```
80
+
81
+ ``` cpp
82
+ constexpr explicit cartesian_product_view(First first_base, Vs... bases);
83
+ ```
84
+
85
+ *Effects:* Initializes *bases\_* with
86
+ `std::move(first_base), std::move(bases)...`.
87
+
88
+ ``` cpp
89
+ constexpr iterator<false> begin()
90
+ requires (!simple-view<First> || ... || !simple-view<Vs>);
91
+ ```
92
+
93
+ *Effects:* Equivalent to:
94
+
95
+ ``` cpp
96
+ return iterator<false>(*this, tuple-transform(ranges::begin, bases_));
97
+ ```
98
+
99
+ ``` cpp
100
+ constexpr iterator<true> begin() const
101
+ requires (range<const First> && ... && range<const Vs>);
102
+ ```
103
+
104
+ *Effects:* Equivalent to:
105
+
106
+ ``` cpp
107
+ return iterator<true>(*this, tuple-transform(ranges::begin, bases_));
108
+ ```
109
+
110
+ ``` cpp
111
+ constexpr iterator<false> end()
112
+ requires ((!simple-view<First> || ... || !simple-view<Vs>)
113
+ && cartesian-product-is-common<First, Vs...>);
114
+ constexpr iterator<true> end() const
115
+ requires cartesian-product-is-common<const First, const Vs...>;
116
+ ```
117
+
118
+ Let:
119
+
120
+ - *is-const* be `true` for the const-qualified overload, and `false`
121
+ otherwise;
122
+ - *is-empty* be `true` if the expression `ranges::empty(rng)` is `true`
123
+ for any `rng` among the underlying ranges except the first one and
124
+ `false` otherwise; and
125
+ - *`begin-or-first-end`*`(rng)` be expression-equivalent to
126
+ *`is-empty`*` ? ranges::begin(rng) : `*`cartesian-common-arg-end`*`(rng)`
127
+ if `rng` is the first underlying range and `ranges::begin(rng)`
128
+ otherwise.
129
+
130
+ *Effects:* Equivalent to:
131
+
132
+ ``` cpp
133
+ iterator<is-const> it(*this, tuple-transform(
134
+ [](auto& rng){ return begin-or-first-end(rng); }, bases_));
135
+ return it;
136
+ ```
137
+
138
+ ``` cpp
139
+ constexpr default_sentinel_t end() const noexcept;
140
+ ```
141
+
142
+ *Returns:* `default_sentinel`.
143
+
144
+ ``` cpp
145
+ constexpr see below size()
146
+ requires cartesian-product-is-sized<First, Vs...>;
147
+ constexpr see below size() const
148
+ requires cartesian-product-is-sized<const First, const Vs...>;
149
+ ```
150
+
151
+ The return type is an *implementation-defined* unsigned-integer-like
152
+ type.
153
+
154
+ *Recommended practice:* The return type should be the smallest
155
+ unsigned-integer-like type that is sufficiently wide to store the
156
+ product of the maximum sizes of all the underlying ranges, if such a
157
+ type exists.
158
+
159
+ Let p be the product of the sizes of all the ranges in *bases\_*.
160
+
161
+ *Preconditions:* p can be represented by the return type.
162
+
163
+ *Returns:* p.
164
+