@@ -31,14 +31,12 @@ using wider_signed_t = std::conditional_t<sizeof(Int) < sizeof(short), short,
31
31
long long >>>;
32
32
// clang-format on
33
33
34
- // iota_diff_t
35
34
template <class Start >
36
35
using iota_diff_t =
37
36
std::conditional_t <(!std::is_integral_v<Start> || sizeof (std::iter_difference_t <Start>) > sizeof (Start)),
38
37
std::iter_difference_t <Start>,
39
38
wider_signed_t <Start>>;
40
39
41
- // __decrementable, __advanceable
42
40
template <class Iter >
43
41
concept decrementable = std::incrementable<Iter> && requires (Iter i) {
44
42
{
@@ -66,18 +64,18 @@ concept advanceable =
66
64
} -> std::convertible_to<iota_diff_t <Iter>>;
67
65
};
68
66
69
- // Iterator
70
67
template <std::incrementable Start>
71
68
class iota_iterator
72
69
{
70
+ private:
73
71
Start value_{};
74
72
75
73
public:
76
- using value_type = Start;
77
- using difference_type = iota_diff_t <value_type>;
78
-
74
+ using value_type = Start;
75
+ using difference_type = iota_diff_t <value_type>;
76
+ using iterator_category = std::input_iterator_tag;
79
77
// clang-format off
80
- using iterator_concept =
78
+ using iterator_concept =
81
79
std::conditional_t <advanceable<value_type>, std::random_access_iterator_tag,
82
80
std::conditional_t <decrementable<value_type>, std::bidirectional_iterator_tag,
83
81
std::forward_iterator_tag>>;
@@ -228,26 +226,27 @@ class iota_iterator
228
226
}
229
227
};
230
228
231
- template <typename Start, typename BoundSentinel >
229
+ template <typename Start, typename Bound >
232
230
class iota_sentinel
233
231
{
234
- BoundSentinel bound_{};
232
+ private:
233
+ Bound bound_{};
235
234
236
235
public:
237
236
constexpr iota_sentinel () = default;
238
- constexpr explicit iota_sentinel (BoundSentinel b) : bound_(std::move(b)) {}
237
+ constexpr explicit iota_sentinel (Bound b) : bound_(std::move(b)) {}
239
238
240
239
friend constexpr bool operator ==(iota_iterator<Start> const & it, iota_sentinel const & sent)
241
240
{
242
241
return *it == sent.bound_ ;
243
242
}
244
243
friend constexpr auto operator -(iota_iterator<Start> const & it, iota_sentinel const & sent)
245
- requires std::sized_sentinel_for<BoundSentinel , Start>
244
+ requires std::sized_sentinel_for<Bound , Start>
246
245
{
247
246
return *it - sent.bound_ ;
248
247
}
249
248
friend constexpr auto operator -(iota_sentinel const & sent, iota_iterator<Start> const & it)
250
- requires std::sized_sentinel_for<BoundSentinel , Start>
249
+ requires std::sized_sentinel_for<Bound , Start>
251
250
{
252
251
return -(it - sent);
253
252
}
@@ -266,15 +265,12 @@ struct iota_fn
266
265
using It = detail::iota_iterator<Value>;
267
266
using Sen = std::conditional_t <std::same_as<Value, Bound>, It, detail::iota_sentinel<Value, Bound>>;
268
267
269
- if constexpr ((std::random_access_iterator<It> && std::same_as<It, Sen>) ||
270
- std::sized_sentinel_for<Bound, Value>)
271
- {
272
- return borrowing_rad<It, Sen, It, Sen, borrowing_rad_kind::sized>{It{val}, It{bound}};
273
- }
274
- else
275
- {
276
- return borrowing_rad<It, Sen, It, Sen, borrowing_rad_kind::unsized>{It{val}, Sen{bound}};
277
- }
268
+ constexpr borrowing_rad_kind kind =
269
+ ((std::random_access_iterator<It> && std::same_as<It, Sen>) || std::sized_sentinel_for<Bound, Value>)
270
+ ? borrowing_rad_kind::sized
271
+ : borrowing_rad_kind::unsized;
272
+
273
+ return borrowing_rad<It, Sen, It, Sen, kind>{It{val}, Sen{bound}};
278
274
}
279
275
};
280
276
@@ -310,7 +306,7 @@ inline constexpr detail::iota_fn iota{};
310
306
* The requirements on the types are weaker than for radr::iota.
311
307
*/
312
308
inline constexpr auto iota_sp =
313
- detail::overloaded{ []<typename Value, typename Bound>(Value val, Bound bound) -> radr::generator<Value>
309
+ []<typename Value, typename Bound = std:: unreachable_sentinel_t >(Value val, Bound bound = {})-> radr::generator<Value>
314
310
{
315
311
static_assert (std::weakly_incrementable<Value>,
316
312
" The Value type to radr::iota_sp needs to satisfy std::weakly_incrementable." );
@@ -322,14 +318,6 @@ inline constexpr auto iota_sp =
322
318
co_yield val;
323
319
++val;
324
320
}
325
- },
326
- []<typename Value>(Value val) -> radr::generator<Value>
327
- {
328
- while (true )
329
- {
330
- co_yield val;
331
- ++val;
332
- }
333
- }};
321
+ };
334
322
335
323
} // namespace radr
0 commit comments