23namespace seqan3::detail
34 constexpr auto operator()(ptrdiff_t begin_pos, ptrdiff_t end_pos)
const noexcept
36 return detail::adaptor_from_functor{*
this, begin_pos, end_pos};
42 template <std::ranges::viewable_range urng_t>
43 constexpr auto operator()(urng_t && urange,
44 std::ranges::range_difference_t<urng_t> begin_pos,
45 std::ranges::range_difference_t<urng_t> end_pos)
const
47 using position_t = std::ranges::range_difference_t<urng_t>;
48 if constexpr (std::ranges::sized_range<urng_t>)
50 position_t urange_size =
static_cast<position_t
>(std::ranges::size(urange));
52 begin_pos =
std::min(begin_pos, urange_size);
53 end_pos =
std::min(end_pos, urange_size);
55 position_t target_size = end_pos - begin_pos;
57 if (end_pos < begin_pos)
58 throw std::invalid_argument{
"end_pos argument to seqan3::views::slice must be >= the begin_pos argument."};
63#if SEQAN3_WORKAROUND_GCC_100139
67 return urange.substr(begin_pos,
static_cast<size_t>(target_size));
70 else if constexpr (is_type_specialisation_of_v<std::remove_cvref_t<urng_t>,
std::basic_string>
71 && std::is_const_v<std::remove_reference_t<urng_t>>)
76 else if constexpr (std::ranges::borrowed_range<urng_t> && std::ranges::contiguous_range<urng_t>
77 && std::ranges::sized_range<urng_t>)
79 return std::span{std::ranges::data(urange) + begin_pos,
static_cast<size_t>(target_size)};
82 else if constexpr (std::ranges::borrowed_range<urng_t> && std::ranges::random_access_range<urng_t>
83 && std::ranges::sized_range<urng_t>)
85 return std::ranges::subrange<std::ranges::iterator_t<urng_t>, std::ranges::iterator_t<urng_t>>{
88 static_cast<size_t>(target_size)};
94 return std::views::take(std::views::drop(std::forward<urng_t>(urange), begin_pos), target_size);
98 return std::views::take(std::views::drop(seqan3::views::type_reduce(std::forward<urng_t>(urange)), begin_pos),
175inline constexpr auto slice = detail::slice_fn{};
Provides seqan3::detail::adaptor_from_functor.
constexpr auto slice
A view adaptor that returns a half-open interval on the underlying range.
Definition slice.hpp:175
Provides exceptions used in the I/O module.
The SeqAn namespace for views.
Definition char_strictly_to.hpp:19
Provides seqan3::views::type_reduce.