51template <std::ranges::view urng_t,
bool or_throw>
52class view_take_exactly :
public std::ranges::view_interface<view_take_exactly<urng_t, or_throw>>
62 template <
bool const_range>
97 if constexpr (std::ranges::sized_range<urng_t>)
101 if constexpr (or_throw)
104 "You are trying to construct a detail::take_exactly_or_throw from a range that is strictly "
121 template <std::ranges::viewable_range rng_t>
122 requires std::constructible_from<rng_t, std::views::all_t<rng_t>>
146 if constexpr (std::ranges::random_access_range<urng_t> && std::ranges::sized_range<urng_t>)
153 constexpr auto begin() const noexcept
156 if constexpr (std::ranges::random_access_range<urng_t> && std::ranges::sized_range<urng_t>)
179 constexpr auto end() noexcept
181 if constexpr (std::ranges::random_access_range<urng_t> && std::ranges::sized_range<urng_t>)
184 return std::ranges::end(
urange);
188 constexpr auto end() const noexcept
191 if constexpr (std::ranges::random_access_range<urng_t> && std::ranges::sized_range<urng_t>)
194 return std::ranges::cend(
urange);
209 constexpr auto size() const noexcept
217template <
typename urng_t,
bool or_throw = false>
222template <std::ranges::view urng_t,
bool or_throw>
223template <
bool const_range>
264 size_t const _max_pos,
266 base_t{
std::move(it)},
272 if constexpr (!std::forward_iterator<base_base_t>)
274 assert(host_ptr !=
nullptr);
279 using typename base_t::difference_type;
280 using typename base_t::reference;
290 base_t::operator++();
292 if constexpr (!std::forward_iterator<base_base_t>)
293 --host_ptr->target_size;
298 constexpr decltype(
auto)
operator++(
int)
noexcept(
noexcept(++std::declval<basic_iterator &>())
299 && (std::same_as<
decltype(std::declval<base_base_t &>()++),
void>
300 || std::is_nothrow_copy_constructible_v<basic_iterator>))
303 if constexpr (std::same_as<decltype(std::declval<base_base_t &>()++),
void>)
319 base_t::operator--();
326 && std::is_nothrow_copy_constructible_v<basic_iterator>)
327 requires std::bidirectional_iterator<base_base_t>
337 requires std::random_access_iterator<base_base_t>
339 base_t::operator+=(skip);
347 requires std::random_access_iterator<base_base_t>
349 base_t::operator-=(skip);
362 noexcept(!or_throw &&
noexcept(std::declval<base_base_t &>() == std::declval<base_base_t &>()))
363 requires std::forward_iterator<base_base_t>
365 return this->base() == rhs.base();
370 noexcept(!or_throw &&
noexcept(std::declval<base_base_t const &>() == std::declval<sentinel_type const &>()))
375 if (this->base() == rhs)
377 if constexpr (or_throw)
397 noexcept(
noexcept(std::declval<basic_iterator &>() == rhs))
399 return !(*
this == rhs);
404 noexcept(
noexcept(std::declval<basic_iterator &>() == rhs))
405 requires std::forward_iterator<base_base_t>
407 return !(*
this == rhs);
428 noexcept(
noexcept(std::declval<base_base_t &>()[0]))
429 requires std::random_access_iterator<base_base_t>
431 return base_t::operator[](n);
443template <
bool or_throw>
455 template <std::ranges::range urng_t>
456 constexpr auto operator()(urng_t && urange,
size_t target_size)
const
458 static_assert(std::ranges::viewable_range<urng_t>,
459 "The views::take adaptor can only be passed viewable_ranges, i.e. Views or &-to-non-View.");
462 if constexpr (std::ranges::sized_range<urng_t>)
464 if constexpr (or_throw)
466 if (target_size > std::ranges::size(urange))
469 "range that is strictly smaller."};
474 target_size = std::min<size_t>(target_size, std::ranges::size(urange));
482 return urange.substr(0, target_size);
485 else if constexpr (is_type_specialisation_of_v<std::remove_cvref_t<urng_t>,
std::basic_string>
486 && std::is_const_v<std::remove_reference_t<urng_t>>)
493 else if constexpr (std::ranges::borrowed_range<urng_t> && std::ranges::contiguous_range<urng_t>
494 && std::ranges::sized_range<urng_t>)
498 return std::span{std::ranges::data(urange), target_size};
501 else if constexpr (std::ranges::borrowed_range<urng_t> && std::ranges::random_access_range<urng_t>
502 && std::ranges::sized_range<urng_t>)
506 return std::ranges::subrange<std::ranges::iterator_t<urng_t>, std::ranges::iterator_t<urng_t>>{
Provides seqan3::detail::adaptor_from_functor.
Template for range adaptor closure objects that store arguments and wrap a proto-adaptor.
Definition: adaptor_from_functor.hpp:57
A CRTP base template for creating iterators that inherit from other iterators.
Definition: inherited_iterator_base.hpp:52
The forward declared iterator type.
Definition: take_exactly_view.hpp:226
basic_iterator()=default
Defaulted.
constexpr basic_iterator(base_base_t it) noexcept(noexcept(base_t{it}))
Constructor that delegates to the CRTP layer.
Definition: take_exactly_view.hpp:258
basic_iterator(basic_iterator &&rhs)=default
Defaulted.
constexpr basic_iterator & operator--() noexcept(noexcept(--std::declval< base_base_t & >()))
Decrements the iterator by one.
Definition: take_exactly_view.hpp:316
constexpr bool operator!=(sentinel_type const &rhs) const noexcept(noexcept(std::declval< basic_iterator & >()==rhs))
Checks whether *this is not equal to rhs.
Definition: take_exactly_view.hpp:396
constexpr basic_iterator & operator-=(difference_type const skip) noexcept(noexcept(std::declval< base_t & >() -=skip))
Advances the iterator by -skip positions.
Definition: take_exactly_view.hpp:345
constexpr basic_iterator operator--(int) noexcept(noexcept(--std::declval< basic_iterator & >()) &&std::is_nothrow_copy_constructible_v< basic_iterator >)
Returns an iterator decremented by one.
Definition: take_exactly_view.hpp:325
basic_iterator & operator=(basic_iterator const &rhs)=default
Defaulted.
constexpr basic_iterator & operator+=(difference_type const skip) noexcept(noexcept(std::declval< base_t & >()+=skip))
Advances the iterator by skip positions.
Definition: take_exactly_view.hpp:335
constexpr friend bool operator!=(sentinel_type const &lhs, basic_iterator const &rhs) noexcept(noexcept(rhs !=lhs))
Checks whether lhs is not equal to rhs.
Definition: take_exactly_view.hpp:411
maybe_const_iterator_t< const_range, urng_t > base_base_t
The iterator type of the underlying range.
Definition: take_exactly_view.hpp:229
constexpr bool operator==(sentinel_type const &rhs) const noexcept(!or_throw &&noexcept(std::declval< base_base_t const & >()==std::declval< sentinel_type const & >()))
Checks whether lhs is equal to rhs.
Definition: take_exactly_view.hpp:369
constexpr bool operator!=(basic_iterator const &rhs) const noexcept(noexcept(std::declval< basic_iterator & >()==rhs))
Checks whether lhs is not equal to rhs.
Definition: take_exactly_view.hpp:403
~basic_iterator()=default
Defaulted.
basic_iterator & operator=(basic_iterator &&rhs)=default
Defaulted.
constexpr friend bool operator==(sentinel_type const &lhs, basic_iterator const &rhs) noexcept(noexcept(rhs==lhs))
Checks whether lhs is equal to rhs.
Definition: take_exactly_view.hpp:389
std::conditional_t<!std::forward_iterator< base_base_t >, view_take_exactly *, detail::ignore_t > host_ptr
A pointer to host, s.t. the size of the view can shrink on pure input ranges.
Definition: take_exactly_view.hpp:243
constexpr basic_iterator & operator++() noexcept(noexcept(++std::declval< base_t & >()))
Increments the iterator by one.
Definition: take_exactly_view.hpp:288
constexpr reference operator[](std::make_unsigned_t< difference_type > const n) const noexcept(noexcept(std::declval< base_base_t & >()[0]))
Accesses an element by index.
Definition: take_exactly_view.hpp:427
maybe_const_sentinel_t< const_range, urng_t > sentinel_type
The sentinel type is identical to that of the underlying range.
Definition: take_exactly_view.hpp:234
constexpr bool operator==(basic_iterator const &rhs) const noexcept(!or_throw &&noexcept(std::declval< base_base_t & >()==std::declval< base_base_t & >()))
Checks whether *this is equal to rhs.
Definition: take_exactly_view.hpp:361
constexpr basic_iterator(base_base_t it, size_t const _pos, size_t const _max_pos, view_take_exactly *host=nullptr) noexcept(noexcept(base_t{it}))
Constructor that delegates to the CRTP layer and initialises the members.
Definition: take_exactly_view.hpp:262
basic_iterator(basic_iterator const &rhs)=default
Defaulted.
The type returned by seqan3::views::take, seqan3::detail::take_exactly and seqan3::detail::take_exact...
Definition: take_exactly_view.hpp:53
size_t target_size
The desired target_size.
Definition: take_exactly_view.hpp:59
view_take_exactly & operator=(view_take_exactly const &rhs)=default
Defaulted.
view_take_exactly & operator=(view_take_exactly &&rhs)=default
Defaulted.
view_take_exactly(view_take_exactly const &rhs)=default
Defaulted.
view_take_exactly(view_take_exactly &&rhs)=default
Defaulted.
constexpr auto begin() noexcept
Returns an iterator to the first element of the container.
Definition: take_exactly_view.hpp:144
view_take_exactly()=default
Defaulted.
constexpr view_take_exactly(urng_t _urange, size_t const _size)
Construct from another View.
Definition: take_exactly_view.hpp:95
~view_take_exactly()=default
Defaulted.
view_take_exactly(urng_t &&, size_t) -> view_take_exactly< std::views::all_t< urng_t >, or_throw >
Template argument type deduction guide that strips references.
constexpr view_take_exactly(rng_t &&_urange, size_t const _size)
Construct from another viewable_range.
Definition: take_exactly_view.hpp:123
constexpr auto end() noexcept
Returns an iterator to the element following the last element of the range.
Definition: take_exactly_view.hpp:179
urng_t urange
The underlying range.
Definition: take_exactly_view.hpp:56
constexpr auto begin() const noexcept
Returns an iterator to the first element of the container.
Definition: take_exactly_view.hpp:153
constexpr auto size() const noexcept
Returns the number of elements in the view.
Definition: take_exactly_view.hpp:209
constexpr auto end() const noexcept
Returns an iterator to the element following the last element of the range.
Definition: take_exactly_view.hpp:188
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: core/range/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: core/range/type_traits.hpp:44
constexpr auto all
Returns a view that includes all elements of the range argument.
Definition: all_view.hpp:204
constexpr auto take_exactly_or_throw
A view adaptor that returns the first size elements from the underlying range and also exposes size i...
Definition: take_exactly_view.hpp:590
constexpr auto take_exactly
A view adaptor that returns the first size elements from the underlying range (or less if the underly...
Definition: take_exactly_view.hpp:576
Provides the seqan3::detail::inherited_iterator_base template.
Specifies requirements of an input range type for which the const version of that type satisfies the ...
Provides exceptions used in the I/O module.
Provides various transformation traits for use on iterators.
The internal SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
SeqAn specific customisations in the standard namespace.
View adaptor definition for views::take and views::take_or_throw.
Definition: take_exactly_view.hpp:445
constexpr auto operator()(size_t const size) const
Store the arguments and return a range adaptor closure object.
Definition: take_exactly_view.hpp:447
constexpr auto operator()(urng_t &&urange, size_t target_size) const
Type erase if possible and return view_take_exactly if not.
Definition: take_exactly_view.hpp:456
Provides type traits for working with templates.
Additional non-standard concepts for ranges.