view: check the index is valid for the subscript operator

This commit is contained in:
Danny Robson 2019-11-05 14:16:31 +11:00
parent b479905b12
commit 762678a50f

View File

@ -340,7 +340,7 @@ namespace cruft {
[[nodiscard]] constexpr auto
split (IndexT idx) const
{
CHECK_LE (cruft::cast::lossless<std::size_t> (idx), size ());
CHECK_LIMIT (idx, IndexT {0u}, cruft::cast::lossless<IndexT> (size ()));
auto last = m_begin;
std::advance (last, idx);
@ -479,6 +479,7 @@ namespace cruft {
constexpr auto&&
operator[] (size_t idx) noexcept
{
CHECK_LIMIT (idx, 0u, size ());
return *std::next (begin (), idx);
}
@ -486,6 +487,7 @@ namespace cruft {
constexpr auto&&
operator[] (size_t idx) const noexcept
{
CHECK_LIMIT (idx, 0u, size ());
return *std::next (begin (), idx);
}