@@ -45,7 +45,7 @@ class chunk_view : public std::ranges::view_interface<chunk_view<urng_t>>
45
45
urng_t urange;
46
46
47
47
// !\brief The chunk size to use.
48
- uint16_t chunk_size;
48
+ std::ranges:: range_difference_t < urng_t > chunk_size;
49
49
50
50
// The iterator type if `urng_t` is a pure input range. See class definition for details.
51
51
template <bool const_range>
@@ -69,11 +69,11 @@ class chunk_view : public std::ranges::view_interface<chunk_view<urng_t>>
69
69
~chunk_view () = default ; // !< Defaulted.
70
70
71
71
/* !\brief Construct from a view and the chunk size.
72
- * \param[in] underlying_range The underlying range to divide into chunks.
72
+ * \param[in] urng The underlying range to divide into chunks.
73
73
* \param[in] size_of_chunk The size of the chunks, e.g., the length of the subrange returned at each position.
74
74
*/
75
- constexpr explicit chunk_view (urng_t underlying_range, uint16_t const size_of_chunk) :
76
- urange{std::move (underlying_range )},
75
+ constexpr explicit chunk_view (urng_t urng, std::ranges:: range_difference_t < urng_t > const size_of_chunk) :
76
+ urange{std::move (urng )},
77
77
chunk_size{size_of_chunk}
78
78
{}
79
79
// !\}
@@ -161,7 +161,7 @@ class chunk_view : public std::ranges::view_interface<chunk_view<urng_t>>
161
161
162
162
// !\brief A deduction guide for the view class template.
163
163
template <std::ranges::range rng_t >
164
- chunk_view (rng_t &&, uint16_t const &) -> chunk_view<seqan3::detail::all_t <rng_t >>;
164
+ chunk_view (rng_t &&, std::ranges:: range_difference_t < rng_t > const &) -> chunk_view<seqan3::detail::all_t <rng_t >>;
165
165
166
166
// ---------------------------------------------------------------------------------------------------------------------
167
167
// chunk_view iterators (basic_input_iterator and basic_iterator)
@@ -319,7 +319,9 @@ class chunk_view<urng_t>::basic_input_iterator :
319
319
*
320
320
* Constant.
321
321
*/
322
- constexpr explicit basic_input_iterator (urng_it_t it_begin, sentinel_t it_end, uint16_t const size_of_chunk) :
322
+ constexpr explicit basic_input_iterator (urng_it_t it_begin,
323
+ sentinel_t it_end,
324
+ std::ranges::range_difference_t <urng_t > const size_of_chunk) :
323
325
chunk_size{size_of_chunk},
324
326
remaining{size_of_chunk},
325
327
urng_begin{std::move (it_begin)},
@@ -374,10 +376,10 @@ class chunk_view<urng_t>::basic_input_iterator :
374
376
375
377
private:
376
378
// !\brief The chunk size, e.g., the length of the subrange returned by this iterator.
377
- uint16_t chunk_size;
379
+ std::ranges:: range_difference_t < urng_t > chunk_size;
378
380
379
381
// !\brief The remaining elements in the chunk.
380
- uint16_t remaining;
382
+ std::ranges:: range_difference_t < urng_t > remaining;
381
383
382
384
// !\brief Points to the start of the underlying range.
383
385
urng_it_t urng_begin;
@@ -469,7 +471,9 @@ class chunk_view<urng_t>::basic_iterator : public maybe_iterator_category<maybe_
469
471
*
470
472
* Linear in chunk_size for non-random_access ranges. Constant else.
471
473
*/
472
- constexpr explicit basic_iterator (it_t it_start, sentinel_t it_end, uint16_t const size_of_chunk) :
474
+ constexpr explicit basic_iterator (it_t it_start,
475
+ sentinel_t it_end,
476
+ std::ranges::range_difference_t <urng_t > const size_of_chunk) :
473
477
chunk_size{size_of_chunk},
474
478
urng_begin{std::move (it_start)},
475
479
urng_end{std::move (it_end)}
@@ -675,7 +679,7 @@ class chunk_view<urng_t>::basic_iterator : public maybe_iterator_category<maybe_
675
679
676
680
private:
677
681
// !\brief The chunk size, e.g. the length of the subrange returned by this iterator.
678
- uint16_t chunk_size;
682
+ std::ranges:: range_difference_t < urng_t > chunk_size;
679
683
680
684
// !\brief Points to the start of the underlying range.
681
685
it_t urng_begin;
@@ -709,8 +713,12 @@ class chunk_view<urng_t>::basic_iterator : public maybe_iterator_category<maybe_
709
713
}
710
714
else // We need to increment one by one to not cross urng_end.
711
715
{
712
- for (uint16_t increments{}; increments != chunk_size && start_of_chunk != urng_end; ++increments)
716
+ for (std::ranges::range_difference_t <urng_t > increments{};
717
+ increments != chunk_size && start_of_chunk != urng_end;
718
+ ++increments)
719
+ {
713
720
++start_of_chunk;
721
+ }
714
722
715
723
return start_of_chunk;
716
724
}
@@ -739,8 +747,12 @@ class chunk_view<urng_t>::basic_iterator : public maybe_iterator_category<maybe_
739
747
}
740
748
else // We need to decrement one by one to not cross urng_begin.
741
749
{
742
- for (uint16_t decrements{}; decrements != chunk_size && end_of_chunk != urng_begin; ++decrements)
750
+ for (std::ranges::range_difference_t <urng_t > decrements{};
751
+ decrements != chunk_size && end_of_chunk != urng_begin;
752
+ ++decrements)
753
+ {
743
754
--end_of_chunk;
755
+ }
744
756
745
757
return end_of_chunk;
746
758
}
@@ -756,7 +768,7 @@ class chunk_view<urng_t>::basic_iterator : public maybe_iterator_category<maybe_
756
768
struct chunk_fn
757
769
{
758
770
// !\brief Store the `chunk_size` and return a range adaptor closure object.
759
- constexpr auto operator ()(uint16_t const chunk_size) const
771
+ constexpr auto operator ()(std:: ptrdiff_t const chunk_size) const
760
772
{
761
773
return adaptor_from_functor{*this , chunk_size};
762
774
}
@@ -766,13 +778,13 @@ struct chunk_fn
766
778
* \param[in] chunk_size The chunk size, e.g. the length of the subrange returned by this iterator.
767
779
* \returns A range of subranges.
768
780
*/
769
- template <std::ranges::range underlying_range_t >
770
- constexpr auto operator ()(underlying_range_t && urange, uint16_t const chunk_size) const
781
+ template <std::ranges::range urng_t >
782
+ constexpr auto operator ()(urng_t && urange, std::ranges:: range_difference_t < urng_t > const chunk_size) const
771
783
{
772
- static_assert (std::ranges::input_range<underlying_range_t >,
784
+ static_assert (std::ranges::input_range<urng_t >,
773
785
" The range parameter to views::chunk must model std::ranges::input_range." );
774
786
775
- return chunk_view{std::forward<underlying_range_t >(urange), chunk_size};
787
+ return chunk_view{std::forward<urng_t >(urange), chunk_size};
776
788
}
777
789
};
778
790
0 commit comments