Skip to content

Commit 390bdfb

Browse files
committed
[nop] minor changes to radr::iota
1 parent f3c56ef commit 390bdfb

File tree

1 file changed

+19
-31
lines changed

1 file changed

+19
-31
lines changed

include/radr/factory/iota.hpp

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@ using wider_signed_t = std::conditional_t<sizeof(Int) < sizeof(short), short,
3131
long long>>>;
3232
// clang-format on
3333

34-
// iota_diff_t
3534
template <class Start>
3635
using iota_diff_t =
3736
std::conditional_t<(!std::is_integral_v<Start> || sizeof(std::iter_difference_t<Start>) > sizeof(Start)),
3837
std::iter_difference_t<Start>,
3938
wider_signed_t<Start>>;
4039

41-
// __decrementable, __advanceable
4240
template <class Iter>
4341
concept decrementable = std::incrementable<Iter> && requires(Iter i) {
4442
{
@@ -66,18 +64,18 @@ concept advanceable =
6664
} -> std::convertible_to<iota_diff_t<Iter>>;
6765
};
6866

69-
// Iterator
7067
template <std::incrementable Start>
7168
class iota_iterator
7269
{
70+
private:
7371
Start value_{};
7472

7573
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;
7977
// clang-format off
80-
using iterator_concept =
78+
using iterator_concept =
8179
std::conditional_t<advanceable<value_type>, std::random_access_iterator_tag,
8280
std::conditional_t<decrementable<value_type>, std::bidirectional_iterator_tag,
8381
std::forward_iterator_tag>>;
@@ -228,26 +226,27 @@ class iota_iterator
228226
}
229227
};
230228

231-
template <typename Start, typename BoundSentinel>
229+
template <typename Start, typename Bound>
232230
class iota_sentinel
233231
{
234-
BoundSentinel bound_{};
232+
private:
233+
Bound bound_{};
235234

236235
public:
237236
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)) {}
239238

240239
friend constexpr bool operator==(iota_iterator<Start> const & it, iota_sentinel const & sent)
241240
{
242241
return *it == sent.bound_;
243242
}
244243
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>
246245
{
247246
return *it - sent.bound_;
248247
}
249248
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>
251250
{
252251
return -(it - sent);
253252
}
@@ -266,15 +265,12 @@ struct iota_fn
266265
using It = detail::iota_iterator<Value>;
267266
using Sen = std::conditional_t<std::same_as<Value, Bound>, It, detail::iota_sentinel<Value, Bound>>;
268267

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}};
278274
}
279275
};
280276

@@ -310,7 +306,7 @@ inline constexpr detail::iota_fn iota{};
310306
* The requirements on the types are weaker than for radr::iota.
311307
*/
312308
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>
314310
{
315311
static_assert(std::weakly_incrementable<Value>,
316312
"The Value type to radr::iota_sp needs to satisfy std::weakly_incrementable.");
@@ -322,14 +318,6 @@ inline constexpr auto iota_sp =
322318
co_yield val;
323319
++val;
324320
}
325-
},
326-
[]<typename Value>(Value val) -> radr::generator<Value>
327-
{
328-
while (true)
329-
{
330-
co_yield val;
331-
++val;
332-
}
333-
}};
321+
};
334322

335323
} // namespace radr

0 commit comments

Comments
 (0)