view: cast to more expressive types when asserting split indices

This commit is contained in:
Danny Robson 2019-11-08 11:17:13 +11:00
parent 762678a50f
commit eb97b5ac01

View File

@ -340,7 +340,13 @@ namespace cruft {
[[nodiscard]] constexpr auto
split (IndexT idx) const
{
CHECK_LIMIT (idx, IndexT {0u}, cruft::cast::lossless<IndexT> (size ()));
// It's ok if `idx` points to the end iterator; this just means the
// second element of the returned pair is an empty view.
static_assert (
std::numeric_limits<IndexT>::max () <= std::numeric_limits<size_type>::max ()
);
CHECK_GE (idx, IndexT {0});
CHECK_LE (cruft::cast::lossless<size_type> (idx), size ());
auto last = m_begin;
std::advance (last, idx);