42 #include <range/v3/algorithm/copy.hpp> 79 template <std::ranges::View urng_t,
bool exactly,
bool or_throw>
80 class view_take :
public ranges::view_interface<view_take<urng_t, exactly, or_throw>>
94 template <
typename rng_t>
95 class iterator_type :
public inherited_iterator_base<iterator_type<rng_t>, std::ranges::iterator_t<rng_t>>
101 using base_t = inherited_iterator_base<iterator_type, std::ranges::iterator_t<rng_t>>;
113 iterator_type() =
default;
114 constexpr iterator_type(iterator_type
const & rhs) =
default;
115 constexpr iterator_type(iterator_type && rhs) =
default;
116 constexpr iterator_type &
operator=(iterator_type
const & rhs) =
default;
117 constexpr iterator_type &
operator=(iterator_type && rhs) =
default;
118 ~iterator_type() =
default;
121 iterator_type(base_base_t
const & it) :
126 iterator_type(base_base_t it,
size_t const _pos,
size_t const _max_pos) :
127 base_t{it}, pos{_pos}, max_pos(_max_pos)
135 using difference_type =
typename std::iterator_traits<base_base_t>::difference_type;
136 using value_type =
typename std::iterator_traits<base_base_t>::value_type;
137 using reference =
typename std::iterator_traits<base_base_t>::reference;
138 using pointer =
typename std::iterator_traits<base_base_t>::pointer;
139 using iterator_category =
typename std::iterator_traits<base_base_t>::iterator_category;
146 iterator_type & operator++() noexcept(noexcept(++base_base_t{}))
148 base_base_t::operator++();
153 iterator_type operator++(
int) noexcept(noexcept(++base_base_t{}))
155 iterator_type cpy{*
this};
160 iterator_type & operator--() noexcept(noexcept(--base_base_t{}))
162 requires
std::BidirectionalIterator<base_base_t>
165 base_base_t::operator--();
170 iterator_type operator--(
int) noexcept(noexcept(--base_base_t{}))
175 iterator_type cpy{*
this};
180 iterator_type & operator+=(difference_type
const skip) noexcept(noexcept(base_base_t{} += skip))
182 requires
std::RandomAccessIterator<base_base_t>
185 base_base_t::operator+=(skip);
190 iterator_type & operator-=(difference_type
const skip) noexcept(noexcept(base_base_t{} -= skip))
192 requires
std::RandomAccessIterator<base_base_t>
195 base_base_t::operator-=(skip);
205 bool operator==(iterator_type
const & rhs)
const noexcept(!or_throw)
207 return static_cast<base_base_t
>(*this) ==
static_cast<base_base_t
>(rhs);
210 bool operator==(sentinel_type
const & rhs)
const noexcept(!or_throw)
215 if (static_cast<base_base_t>(*
this) == rhs)
217 if constexpr (or_throw)
218 throw unexpected_end_of_input{
"Reached end of input before designated size."};
228 friend bool operator==(sentinel_type
const & lhs, iterator_type
const & rhs) noexcept(!or_throw)
233 bool operator!=(sentinel_type
const & rhs)
const noexcept(!or_throw)
235 return !(*
this == rhs);
238 bool operator!=(iterator_type
const & rhs)
const noexcept(!or_throw)
240 return static_cast<base_base_t
>(*this) !=
static_cast<base_base_t
>(rhs);
243 friend bool operator!=(sentinel_type
const & lhs, iterator_type
const & rhs) noexcept(!or_throw)
253 reference operator[](std::make_unsigned_t<difference_type>
const n)
const noexcept(noexcept(base_base_t{}[0]))
255 requires
std::RandomAccessIterator<base_base_t>
259 return base_base_t::operator[](n);
268 using reference = reference_t<urng_t>;
271 using const_reference = detail::transformation_trait_or_t<seqan3::reference<urng_t const>,
void>;
273 using value_type = value_type_t<urng_t>;
275 using size_type = std::conditional_t<exactly, size_t, void>;
277 using difference_type = difference_type_t<urng_t>;
279 using iterator = iterator_type<urng_t>;
281 using const_iterator = detail::transformation_trait_or_t<std::type_identity<iterator_type<urng_t const>>,
void>;
287 view_take() =
default;
288 constexpr view_take(view_take
const & rhs) =
default;
289 constexpr view_take(view_take && rhs) =
default;
290 constexpr view_take &
operator=(view_take
const & rhs) =
default;
291 constexpr view_take &
operator=(view_take && rhs) =
default;
292 ~view_take() =
default;
299 view_take(urng_t _urange,
size_t const _size)
300 : urange{std::move(_urange)}, target_size{_size}
306 throw std::invalid_argument{
307 "You are trying to construct a view::take_exactly_or_throw from a range that is strictly smaller."};
329 iterator
begin() noexcept
331 return {seqan3::begin(urange), 0, target_size};
335 const_iterator
begin() const noexcept
336 requires const_iterable_concept<urng_t>
342 const_iterator
cbegin() const noexcept
343 requires const_iterable_concept<urng_t>
361 sentinel_type
end() noexcept
363 return {seqan3::end(urange)};
367 sentinel_type
end() const noexcept
368 requires const_iterable_concept<urng_t>
374 sentinel_type
cend() const noexcept
375 requires const_iterable_concept<urng_t>
392 size_type
size() const noexcept
403 template <sequence_container_concept container_t>
404 operator container_t()
406 requires
std::CommonReference<
reference_t<container_t>, reference>
415 template <sequence_container_concept container_t>
416 operator container_t() const
418 requires
std::CommonReference<
reference_t<container_t>, reference> && const_iterable_concept<urng_t>
429 template <
typename urng_t,
430 bool exactly =
false,
431 bool or_throw =
false>
432 view_take(urng_t,
size_t) -> view_take<std::remove_reference_t<urng_t>, exactly, or_throw>;
441 template <
bool exactly,
bool or_throw>
442 class take_fn :
public pipable_adaptor_base<take_fn<exactly, or_throw>>
446 using base_t = pipable_adaptor_base<take_fn<exactly, or_throw>>;
450 using base_t::base_t;
459 template <std::ranges::View urng_t>
460 static auto impl(urng_t urange,
size_t const target_size)
462 return view_take<urng_t, exactly, or_throw>{std::move(urange), target_size};
468 template <std::ranges::ViewableRange urng_t>
469 static auto impl(urng_t && urange,
size_t const target_size)
471 return impl(
view::all(std::forward<urng_t>(urange)), target_size);
526 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:245
Provides exceptions used in the I/O module.
Provides C++20 additions to the <iterator> header.
Contains various shortcuts for common std::ranges functions.
Provides the seqan3::detail::inherited_iterator_base template.
SeqAn specific customisations in the standard namespace.
Definition: align_result.hpp:221
::ranges::copy copy
Alias for ranges::copy. Copies a range of elements to a new location.
Definition: ranges:200
::ranges::size size
Alias for ranges::size. Obtains the size of a range whose size can be calculated in constant time...
Definition: ranges:195
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:225
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:220
::ranges::begin begin
Alias for ranges::begin. Returns an iterator to the beginning of a range.
Definition: ranges:185
Provides seqan3::view::all.
The SeqAn3 namespace for views.
Definition: aligned_sequence_concept.hpp:288
Provides C++20 additions to the type_traits header.
The concept BidirectionalIterator refines std::ForwardIterator by adding the ability to move an itera...
constexpr auto all
A view that safely wraps a container (you will likely not need to use this unless defining a new view...
Definition: view_all.hpp:95
Provides various metafunctions used by the range module.
Provides various metafunctions for use on iterators.
auto constexpr take
A view adaptor that returns the first size elements from the underlying range (or less if the underly...
Definition: take.hpp:526
::ranges::cend cend
Alias for ranges::cend. Returns an iterator to the end of a range.
Definition: ranges:250
Adaptations of concepts from the standard library.
constexpr auto back_inserter(container_t &container)
Create a std::back_insert_iterator for the argument.
Definition: iterator:79
Specifies the requirements of a Range type that knows its size in constant time with the size functio...
::ranges::end end
Alias for ranges::end. Returns an iterator to the end of a range.
Definition: ranges:190