Skip to content

Commit

Permalink
Merge pull request #2529 from marehr/gcc-11-3
Browse files Browse the repository at this point in the history
[FIX] gcc-11: slice should take range_difference_t
  • Loading branch information
eseiler authored Apr 20, 2021
2 parents 9f2c1cc + 274db62 commit 92e5067
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions include/seqan3/range/views/slice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,22 @@ struct slice_fn
* \returns An instance of seqan3::detail::view_slice.
*/
template <std::ranges::viewable_range urng_t>
constexpr auto operator()(urng_t && urange, ptrdiff_t begin_pos, ptrdiff_t end_pos) const
constexpr auto operator()(urng_t && urange,
std::ranges::range_difference_t<urng_t> begin_pos,
std::ranges::range_difference_t<urng_t> end_pos) const
{
if constexpr (std::ranges::sized_range<urng_t>)
{
begin_pos = std::min(begin_pos, static_cast<ptrdiff_t>(std::ranges::size(urange)));
end_pos = std::min(end_pos, static_cast<ptrdiff_t>(std::ranges::size(urange)));
using position_t = std::ranges::range_difference_t<urng_t>;
begin_pos = std::min(begin_pos, static_cast<position_t>(std::ranges::size(urange)));
end_pos = std::min(end_pos, static_cast<position_t>(std::ranges::size(urange)));
}

if (end_pos < begin_pos)
throw std::invalid_argument{"end_pos argument to seqan3::views::slice must be >= the begin_pos argument."};

return std::forward<urng_t>(urange) | views::drop(begin_pos) | views::take(end_pos - begin_pos);
// urange | drop | take
return views::take(views::drop(std::forward<urng_t>(urange), begin_pos), end_pos - begin_pos);
}

// does not require special overloads, because views::drop and views::take handle the flattening.
Expand Down

1 comment on commit 92e5067

@vercel
Copy link

@vercel vercel bot commented on 92e5067 Apr 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.