15 #include <range/v3/algorithm/copy.hpp> 54 template <std::ranges::View urng_t,
bool exactly,
bool or_throw>
69 template <
typename rng_t>
70 class iterator_type :
public inherited_iterator_base<iterator_type<rng_t>, std::ranges::iterator_t<rng_t>>
76 using base_t = inherited_iterator_base<iterator_type, std::ranges::iterator_t<rng_t>>;
92 constexpr iterator_type() =
default;
93 constexpr iterator_type(iterator_type
const & rhs) =
default;
94 constexpr iterator_type(iterator_type && rhs) =
default;
95 constexpr iterator_type &
operator=(iterator_type
const & rhs) =
default;
96 constexpr iterator_type &
operator=(iterator_type && rhs) =
default;
97 ~iterator_type() =
default;
100 constexpr iterator_type(base_base_t
const & it) noexcept(noexcept(base_t{it})) :
101 base_t{std::move(it)}
105 constexpr iterator_type(base_base_t it,
size_t const _pos,
size_t const _max_pos, view_take * host =
nullptr) noexcept(noexcept(base_t{it})) :
106 base_t{std::move(it)}, pos{_pos}, max_pos(_max_pos)
126 using iterator_category = iterator_tag_t<base_base_t>;
134 constexpr iterator_type & operator++() noexcept(noexcept(++
std::declval<base_t &>()))
137 base_t::operator++();
140 --host_ptr->target_size;
145 constexpr iterator_type operator++(
int) noexcept(noexcept(++std::declval<iterator_type &>()) &&
146 std::is_nothrow_copy_constructible_v<iterator_type>)
148 iterator_type cpy{*
this};
154 constexpr iterator_type & operator--() noexcept(noexcept(--
std::declval<base_base_t &>()))
156 requires
std::BidirectionalIterator<base_base_t>
159 base_t::operator--();
165 constexpr iterator_type operator--(
int) noexcept(noexcept(--std::declval<iterator_type &>()) &&
166 std::is_nothrow_copy_constructible_v<iterator_type>)
171 iterator_type cpy{*
this};
177 constexpr iterator_type & operator+=(difference_type
const skip) noexcept(noexcept(std::declval<base_t &>() += skip))
182 base_t::operator+=(skip);
188 constexpr iterator_type & operator-=(difference_type
const skip) noexcept(noexcept(std::declval<base_t &>() -= skip))
193 base_t::operator-=(skip);
204 constexpr
bool operator==(iterator_type
const & rhs)
const 206 noexcept(!or_throw && noexcept(std::declval<base_base_t &>() == std::declval<base_base_t &>()))
208 requires
std::ForwardIterator<base_base_t>
211 return *base_t::this_to_base() == *rhs.this_to_base();
215 constexpr
bool operator==(sentinel_type
const & rhs)
const 216 noexcept(!or_throw && noexcept(std::declval<base_base_t &>() == std::declval<sentinel_type &>()))
221 if (*base_t::this_to_base() == rhs)
223 if constexpr (or_throw)
224 throw unexpected_end_of_input{
"Reached end of input before designated size."};
235 constexpr
friend bool operator==(sentinel_type
const & lhs, iterator_type
const & rhs) noexcept(noexcept(rhs == lhs))
241 constexpr
bool operator!=(sentinel_type
const & rhs)
const 242 noexcept(noexcept(std::declval<iterator_type &>() == rhs))
244 return !(*
this == rhs);
248 constexpr
bool operator!=(iterator_type
const & rhs)
const 249 noexcept(noexcept(std::declval<iterator_type &>() == rhs))
254 return !(*
this == rhs);
258 constexpr
friend bool operator!=(sentinel_type
const & lhs, iterator_type
const & rhs) noexcept(noexcept(rhs != lhs))
274 noexcept(noexcept(std::declval<base_base_t &>()[0]))
276 requires
std::RandomAccessIterator<base_base_t>
279 return base_base_t::operator[](n);
288 using reference = reference_t<urng_t>;
291 using const_reference = detail::transformation_trait_or_t<seqan3::reference<urng_t const>,
void>;
293 using value_type = value_type_t<urng_t>;
296 transformation_trait_or_t<seqan3::size_type<urng_t>,
size_t>,
299 using difference_type = difference_type_t<urng_t>;
301 using iterator = iterator_type<urng_t>;
303 using const_iterator = detail::transformation_trait_or_t<std::type_identity<iterator_type<urng_t const>>,
void>;
309 constexpr view_take() =
default;
310 constexpr view_take(view_take
const & rhs) =
default;
311 constexpr view_take(view_take && rhs) =
default;
312 constexpr view_take &
operator=(view_take
const & rhs) =
default;
313 constexpr view_take &
operator=(view_take && rhs) =
default;
314 ~view_take() =
default;
321 constexpr view_take(urng_t _urange,
size_t const _size)
322 : urange{std::move(_urange)}, target_size{_size}
329 "You are trying to construct a view::take_exactly_or_throw from a range that is strictly smaller."};
340 template<std::ranges::ViewableRange rng_t>
344 constexpr view_take(rng_t && _urange,
size_t const _size)
365 constexpr iterator
begin() noexcept
371 constexpr const_iterator
begin() const noexcept
372 requires ConstIterableRange<urng_t>
378 constexpr const_iterator
cbegin() const noexcept
379 requires ConstIterableRange<urng_t>
397 constexpr sentinel_type
end() noexcept
403 constexpr sentinel_type
end() const noexcept
404 requires ConstIterableRange<urng_t>
410 constexpr sentinel_type
cend() const noexcept
411 requires ConstIterableRange<urng_t>
428 constexpr size_type
size() const noexcept
437 template <
typename urng_t,
438 bool exactly =
false,
439 bool or_throw =
false>
440 view_take(urng_t && ,
size_t) -> view_take<std::ranges::all_view<urng_t>, exactly, or_throw>;
449 template <
bool exactly,
bool or_throw>
453 constexpr
auto operator()(
size_t const size)
const 455 return adaptor_from_functor{*
this,
size};
461 template <std::ranges::Range urng_t>
462 constexpr
auto operator()(urng_t && urange,
size_t target_size)
const 465 "The view::take adaptor can only be passed ViewableRanges, i.e. Views or &-to-non-View.");
470 if constexpr (or_throw)
475 "range that is strictly smaller."};
487 return urange.substr(0, target_size);
490 else if constexpr (is_type_specialisation_of_v<remove_cvref_t<urng_t>,
std::basic_string> &&
496 else if constexpr (ForwardingRange<urng_t> &&
503 else if constexpr (ForwardingRange<urng_t> &&
517 return view_take<std::ranges::all_view<urng_t>, exactly, or_throw>
519 std::forward<urng_t>(urange),
596 inline auto constexpr
take = detail::take_fn<false, false>{};
::ranges::cbegin cbegin
Alias for ranges::cbegin. Returns an iterator to the beginning of a range.
Definition: ranges:209
Specifies the requirements of a Range type that is either a std::ranges::View or an lvalue-reference...
::ranges::subrange< it_t, sen_t, k > subrange
Create a view from a pair of iterator and sentinel.
Definition: ranges:339
Provides exceptions used in the I/O module.
Specifies requirements of a Range type whose elements occupy adjacent locations in memory...
Provides C++20 additions to the <iterator> header.
Provides various shortcuts for common std::ranges functions.
Provides seqan3::type_list and auxiliary type traits.
Specifies requirements of a Range type for which begin returns a type that models std::RandomAccessIt...
Provides the seqan3::detail::inherited_iterator_base template.
The InputIterator concept is a refinement of std::Iterator, adding the requirement that the reference...
SeqAn specific customisations in the standard namespace.
constexpr auto all
A view adaptor that behaves like std::view:all, but type erases contiguous ranges.
Definition: view_all.hpp:160
::ranges::size size
Alias for ranges::size. Obtains the size of a range whose size can be calculated in constant time...
Definition: ranges:189
::ranges::data data
Alias for ranges::data. Returns a pointer the block of data of a ContiguousRange. ...
Definition: ranges:184
::ranges::view_interface< urng_t > view_interface
Alias for ranges::view_interface.
Definition: ranges:220
Specifies the requirements of a Range type that knows its size in constant time with the size functio...
Provides various transformation traits for use on iterators.
t & operator=(t1 const &rhs)
Assignment operator.
Additional non-standard concepts for ranges.
Auxiliary header for the view submodule .
::ranges::iterator_t iterator_t
Alias for ranges::iterator_t. Obtains the iterator type of a range.
Definition: ranges:204
Adaptations of concepts from the Ranges TS.
::ranges::sentinel_t sentinel_t
Alias for ranges::sentinel_t. Obtains the sentinel type of a range.
Definition: ranges:199
::ranges::begin begin
Alias for ranges::begin. Returns an iterator to the beginning of a range.
Definition: ranges:174
The SeqAn3 namespace for views.
Provides std::span from the C++20 standard library.
Definition: aligned_sequence_concept.hpp:35
The concept RandomAccessIterator refines std::BidirectionalIterator by adding support for constant ti...
The std::Constructible concept specifies that a variable of type T can be initialized with the given ...
Provides C++20 additions to the type_traits header.
The concept BidirectionalIterator refines std::ForwardIterator by adding the ability to move an itera...
Adaptations of algorithms from the Ranges TS.
Provides various transformation traits used by the range module.
auto constexpr take
A view adaptor that returns the first size elements from the underlying range (or less if the underly...
Definition: take.hpp:596
::ranges::cend cend
Alias for ranges::cend. Returns an iterator to the end of a range.
Definition: ranges:214
Adaptations of concepts from the standard library.
::ranges::end end
Alias for ranges::end. Returns an iterator to the end of a range.
Definition: ranges:179