39template <std::ranges::input_range urng_t>
40 requires std::ranges::view<urng_t>
41class chunk_view :
public std::ranges::view_interface<chunk_view<urng_t>>
51 template <
bool const_range>
55 template <
bool const_range>
63 requires std::default_initializable<urng_t>
75 constexpr explicit
chunk_view(urng_t underlying_range, uint16_t const size_of_chunk) :
76 urange{std::move(underlying_range)},
99 if constexpr (std::ranges::forward_range<urng_t>)
109 if constexpr (std::ranges::forward_range<urng_t>)
132 return std::ranges::end(
urange);
139 return std::ranges::cend(
urange);
147 requires std::ranges::sized_range<urng_t>
149 using size_type = std::ranges::range_size_t<urng_t>;
155 requires
std::ranges::sized_range<urng_t const>
157 using size_type = std::ranges::range_size_t<urng_t const>;
163template <std::ranges::range rng_t>
187template <std::ranges::input_range urng_t>
188 requires std::ranges::view<urng_t>
189template <
bool const_range>
212 template <
typename outer_it_type>
229 outer_it(
std::addressof(outer_iterator))
240 --(outer_it->remaining);
241 urng_it_t::operator++();
256 return this->outer_it->remaining == 0u || this->outer_it->urng_begin == this->outer_it->urng_end;
260 outer_it_type * outer_it{
nullptr};
267 template <
bool other_const_range>
271 template <
typename outer_it_type>
281 using value_type = std::ranges::subrange<helper_it_t, sentinel_t>;
305 remaining{std::move(it.remaining)},
306 urng_begin{std::move(it.urng_begin)},
307 urng_end{std::move(it.urng_end)},
308 current_chunk{std::move(it.current_chunk)}
324 remaining{size_of_chunk},
325 urng_begin{
std::move(it_begin)},
326 urng_end{
std::move(it_end)}
328 current_chunk = std::ranges::subrange<helper_it_t, sentinel_t>{
helper_it_t{*
this, it_begin}, it_end};
339 return lhs.urng_begin == rhs;
345 return (lhs.urng_begin == rhs.urng_begin) && (lhs.remaining == rhs.remaining);
351 while (remaining > 0u && urng_begin != urng_end)
356 current_chunk = std::ranges::subrange<helper_it_t, sentinel_t>{
helper_it_t{*
this, urng_begin}, urng_end};
372 return current_chunk;
408template <std::ranges::input_range urng_t>
409 requires std::ranges::view<urng_t>
410template <
bool const_range>
420 template <
bool other_const_range>
456 urng_begin{std::move(it.urng_begin)},
457 urng_end{std::move(it.urng_end)},
458 current_chunk{std::move(it.current_chunk)}
474 urng_begin{
std::move(it_start)},
475 urng_end{
std::move(it_end)}
477 current_chunk =
value_type{it_start, get_next_end_of_chunk(it_start)};
488 return lhs.current_chunk.begin() == rhs;
494 return (lhs.current_chunk.begin() == rhs.current_chunk.begin()) && (lhs.chunk_size == rhs.chunk_size);
500 return !(lhs == rhs);
506 return !(lhs == rhs);
512 return lhs.current_chunk.begin() < rhs.current_chunk.begin();
518 return lhs.current_chunk.begin() > rhs.current_chunk.begin();
524 return lhs.current_chunk.begin() <= rhs.current_chunk.begin();
530 return lhs.current_chunk.begin() >= rhs.current_chunk.begin();
538 current_chunk =
value_type{current_chunk.end(), get_next_end_of_chunk(current_chunk.end())};
554 requires
std::bidirectional_iterator<
it_t>
556 current_chunk =
value_type{get_former_start_of_chunk(current_chunk.begin()), current_chunk.begin()};
564 requires std::bidirectional_iterator<it_t>
575 requires std::random_access_iterator<it_t>
577 auto new_start_it = current_chunk.begin() + (
chunk_size * skip);
578 current_chunk =
value_type{new_start_it, get_next_end_of_chunk(new_start_it)};
586 requires std::random_access_iterator<it_t>
596 requires std::random_access_iterator<it_t>
605 requires std::random_access_iterator<it_t>
607 auto new_start_it = current_chunk.begin() - (
chunk_size * skip);
608 current_chunk =
value_type{new_start_it, get_next_end_of_chunk(new_start_it)};
617 requires std::random_access_iterator<it_t>
627 requires std::random_access_iterator<it_t>
637 requires std::sized_sentinel_for<it_t, it_t>
639 return static_cast<difference_type>((lhs.current_chunk.begin() - rhs.current_chunk.begin()) / lhs.chunk_size);
646 requires std::sized_sentinel_for<sentinel_t, it_t>
648 return static_cast<difference_type>((rhs.urng_end - rhs.current_chunk.begin() + rhs.chunk_size - 1)
656 requires std::sized_sentinel_for<sentinel_t, it_t>
665 requires std::random_access_iterator<it_t>
673 return current_chunk;
703 if constexpr (std::sized_sentinel_for<sentinel_t, it_t>)
705 if (
chunk_size >= std::abs(urng_end - start_of_chunk))
706 return std::ranges::next(start_of_chunk, urng_end);
708 return std::ranges::next(start_of_chunk,
chunk_size);
712 for (uint16_t increments{}; increments !=
chunk_size && start_of_chunk != urng_end; ++increments)
715 return start_of_chunk;
733 if constexpr (std::sized_sentinel_for<sentinel_t, it_t>)
735 if (
chunk_size >= std::abs(urng_begin - end_of_chunk))
738 return std::ranges::prev(end_of_chunk,
chunk_size);
742 for (uint16_t decrements{}; decrements !=
chunk_size && end_of_chunk != urng_begin; ++decrements)
769 template <std::ranges::range underlying_range_t>
770 constexpr auto operator()(underlying_range_t && urange, uint16_t
const chunk_size)
const
772 static_assert(std::ranges::input_range<underlying_range_t>,
773 "The range parameter to views::chunk must model std::ranges::input_range.");
775 return chunk_view{std::forward<underlying_range_t>(urange), chunk_size};
Provides seqan3::detail::adaptor_from_functor.
Provides seqan3::detail::all.
Core alphabet concept and free function/type trait wrappers.
Template for range adaptor closure objects that store arguments and wrap a proto-adaptor.
Definition: adaptor_from_functor.hpp:57
Iterator for dividing an forward range into chunks.
Definition: chunk.hpp:412
constexpr basic_iterator operator+(difference_type const skip) const noexcept
Forward copy of this iterator.
Definition: chunk.hpp:585
friend constexpr bool operator==(basic_iterator const &lhs, basic_iterator const &rhs) noexcept
Compare to another basic_iterator.
Definition: chunk.hpp:492
std::ranges::subrange< it_t, it_t > value_type
Value type of this iterator.
Definition: chunk.hpp:430
uint16_t chunk_size
The chunk size, e.g. the length of the subrange returned by this iterator.
Definition: chunk.hpp:678
friend constexpr bool operator<=(basic_iterator const &lhs, basic_iterator const &rhs) noexcept
Compare to another basic_iterator.
Definition: chunk.hpp:522
maybe_const_iterator_t< const_range, urng_t > it_t
The iterator type of the underlying range.
Definition: chunk.hpp:415
basic_iterator operator++(int) noexcept
Post-increment.
Definition: chunk.hpp:543
friend constexpr bool operator>=(basic_iterator const &lhs, basic_iterator const &rhs) noexcept
Compare to another basic_iterator.
Definition: chunk.hpp:528
friend constexpr basic_iterator operator-(difference_type const skip, basic_iterator const &it) noexcept
Non-member operator- delegates to non-friend operator-.
Definition: chunk.hpp:626
constexpr basic_iterator & operator--() noexcept
Pre-decrement.
Definition: chunk.hpp:553
friend constexpr bool operator==(basic_iterator const &lhs, sentinel_t const &rhs) noexcept
Compare to end of underlying range.
Definition: chunk.hpp:486
friend constexpr basic_iterator operator+(difference_type const skip, basic_iterator const &it) noexcept
Non-member operator+ delegates to non-friend operator+.
Definition: chunk.hpp:595
constexpr value_type operator*() const noexcept
Return the current chunk, e.g the current subrange.
Definition: chunk.hpp:671
maybe_const_sentinel_t< const_range, urng_t > sentinel_t
The sentinel type of the underlying range.
Definition: chunk.hpp:417
constexpr basic_iterator & operator++() noexcept
Pre-increment.
Definition: chunk.hpp:536
value_type reference
Same as value_type.
Definition: chunk.hpp:434
constexpr basic_iterator(it_t it_start, sentinel_t it_end, uint16_t const size_of_chunk)
Construct from the start and end of the underlying range and a chunk size. /param[in] it_start Iterat...
Definition: chunk.hpp:472
friend constexpr difference_type operator-(basic_iterator const &lhs, basic_iterator const &rhs) noexcept
Return offset between two iterator's positions.
Definition: chunk.hpp:636
sentinel_t urng_end
Points to the end of the underlying range.
Definition: chunk.hpp:684
friend constexpr bool operator<(basic_iterator const &lhs, basic_iterator const &rhs) noexcept
Compare to another basic_iterator.
Definition: chunk.hpp:510
constexpr reference operator[](difference_type const n) const
Move the iterator by a given offset and return the corresponding chunk (subrange).
Definition: chunk.hpp:664
typename std::iter_difference_t< it_t > difference_type
Type for distances between iterators.
Definition: chunk.hpp:428
constexpr it_t get_former_start_of_chunk(it_t end_of_chunk) const
Move to the start of the former chunk.
Definition: chunk.hpp:720
friend constexpr difference_type operator-(sentinel_t const &, basic_iterator const &rhs) noexcept
Return offset between remote sentinel's position and this.
Definition: chunk.hpp:645
~basic_iterator()=default
Defaulted.
void pointer
The pointer type.
Definition: chunk.hpp:432
constexpr basic_iterator()=default
Defaulted.
constexpr basic_iterator & operator+=(difference_type const skip) noexcept
Forward this iterator.
Definition: chunk.hpp:574
friend constexpr bool operator!=(basic_iterator const &lhs, basic_iterator const &rhs) noexcept
Compare to another basic_iterator.
Definition: chunk.hpp:504
constexpr basic_iterator(basic_iterator &&)=default
Defaulted.
friend constexpr bool operator>(basic_iterator const &lhs, basic_iterator const &rhs) noexcept
Compare to another basic_iterator.
Definition: chunk.hpp:516
it_t urng_begin
Points to the start of the underlying range.
Definition: chunk.hpp:681
constexpr basic_iterator & operator=(basic_iterator &&)=default
Defaulted.
value_type current_chunk
The current chunk stored as a subrange.
Definition: chunk.hpp:687
constexpr basic_iterator(basic_iterator<!const_range > const &it) noexcept
Allow iterator on a const range to be constructible from an iterator over a non-const range.
Definition: chunk.hpp:452
constexpr basic_iterator & operator=(basic_iterator const &)=default
Defaulted.
constexpr basic_iterator & operator-=(difference_type const skip) noexcept
Decrement iterator by skip.
Definition: chunk.hpp:604
constexpr basic_iterator(basic_iterator const &)=default
Defaulted.
friend constexpr difference_type operator-(basic_iterator const &lhs, sentinel_t const &rhs) noexcept
Return offset this and remote sentinel's position.
Definition: chunk.hpp:655
constexpr basic_iterator operator-(difference_type const skip) const noexcept
Return decremented copy of this iterator.
Definition: chunk.hpp:616
friend constexpr bool operator!=(basic_iterator const &lhs, sentinel_t const &rhs) noexcept
Compare to underlying range sentinel type.
Definition: chunk.hpp:498
constexpr basic_iterator operator--(int) noexcept
Post-decrement.
Definition: chunk.hpp:563
constexpr it_t get_next_end_of_chunk(it_t start_of_chunk) const
Move to the end of the next chunk.
Definition: chunk.hpp:690
The type returned by seqan3::views::chunk.
Definition: chunk.hpp:42
chunk_view()=default
Defaulted.
auto end() const noexcept
Returns an iterator to the element following the last element of the range.
Definition: chunk.hpp:136
auto size() const
Returns the size of the range, iff the underlying range is a std::ranges::sized_range.
Definition: chunk.hpp:154
auto begin() noexcept
Returns an iterator to the first element of the range.
Definition: chunk.hpp:97
urng_t urange
The underlying range.
Definition: chunk.hpp:45
auto end() noexcept
Returns an iterator to the element following the last element of the range.
Definition: chunk.hpp:130
uint16_t chunk_size
The chunk size to use.
Definition: chunk.hpp:48
auto begin() const noexcept
Returns an iterator to the first element of the range.
Definition: chunk.hpp:106
auto size()
Returns the size of the range, iff the underlying range is a std::ranges::sized_range.
Definition: chunk.hpp:146
Provides various transformation traits used by the range module.
std::ranges::sentinel_t< maybe_const_range_t< const_v, range_t > > maybe_const_sentinel_t
Returns the const sentinel of range_t if const_range is true; otherwise the non-const sentinel.
Definition: type_traits.hpp:49
std::ranges::iterator_t< maybe_const_range_t< const_range, range_t > > maybe_const_iterator_t
Returns the const iterator of range_t if const_range is true; otherwise the non-const iterator.
Definition: type_traits.hpp:44
constexpr size_t size
The size of a type pack.
Definition: traits.hpp:146
constexpr auto chunk
Divide a range in chunks.
Definition: chunk.hpp:823
Specifies requirements of an input range type for which the const version of that type satisfies the ...
Provides various transformation traits for use on iterators.
The internal SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
chunk_view(rng_t &&, uint16_t const &) -> chunk_view< seqan3::detail::all_t< rng_t > >
A deduction guide for the view class template.
The SeqAn namespace for views.
Definition: char_strictly_to.hpp:22
SeqAn specific customisations in the standard namespace.
The <ranges> header from C++20's standard library.
views::chunk's range adaptor object type (non-closure).
Definition: chunk.hpp:757
constexpr auto operator()(underlying_range_t &&urange, uint16_t const chunk_size) const
Call the view's constructor with the underlying range and a chunk_size as argument.
Definition: chunk.hpp:770
constexpr auto operator()(uint16_t const chunk_size) const
Store the chunk_size and return a range adaptor closure object.
Definition: chunk.hpp:759
Defines iterator_category member if underlying_iterator_t has a valid std::iterator_traits::iterator_...
Definition: iterator_traits.hpp:42
Additional non-standard concepts for ranges.