mirror of
https://github.com/matrix-construct/construct
synced 2024-12-27 07:54:05 +01:00
ircd::vector_view: Add assertion for bounds check here.
This commit is contained in:
parent
0aacf44440
commit
7420bf1156
1 changed files with 7 additions and 1 deletions
|
@ -46,15 +46,21 @@ struct ircd::vector_view
|
|||
iterator begin() { return data(); }
|
||||
iterator end() { return _stop; }
|
||||
|
||||
// Bounds check in debug only.
|
||||
value_type &operator[](const size_t &pos) const
|
||||
{
|
||||
assert(pos < size());
|
||||
return *(data() + pos);
|
||||
}
|
||||
|
||||
// Bounds check at runtime.
|
||||
value_type &at(const size_t &pos) const
|
||||
{
|
||||
if(unlikely(pos >= size()))
|
||||
throw std::out_of_range("vector_view::range_check");
|
||||
throw std::out_of_range
|
||||
{
|
||||
"vector_view::range_check"
|
||||
};
|
||||
|
||||
return operator[](pos);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue