view: check the index is valid for the subscript operator
This commit is contained in:
parent
b479905b12
commit
762678a50f
4
view.hpp
4
view.hpp
@ -340,7 +340,7 @@ namespace cruft {
|
|||||||
[[nodiscard]] constexpr auto
|
[[nodiscard]] constexpr auto
|
||||||
split (IndexT idx) const
|
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;
|
auto last = m_begin;
|
||||||
std::advance (last, idx);
|
std::advance (last, idx);
|
||||||
@ -479,6 +479,7 @@ namespace cruft {
|
|||||||
constexpr auto&&
|
constexpr auto&&
|
||||||
operator[] (size_t idx) noexcept
|
operator[] (size_t idx) noexcept
|
||||||
{
|
{
|
||||||
|
CHECK_LIMIT (idx, 0u, size ());
|
||||||
return *std::next (begin (), idx);
|
return *std::next (begin (), idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -486,6 +487,7 @@ namespace cruft {
|
|||||||
constexpr auto&&
|
constexpr auto&&
|
||||||
operator[] (size_t idx) const noexcept
|
operator[] (size_t idx) const noexcept
|
||||||
{
|
{
|
||||||
|
CHECK_LIMIT (idx, 0u, size ());
|
||||||
return *std::next (begin (), idx);
|
return *std::next (begin (), idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user