fix assertion messages for bounded_vector::back() method

This commit is contained in:
Francisco 2020-12-03 19:52:20 +00:00 committed by Andre Puschmann
parent 5cce2e4dc7
commit 7ee99a529a
1 changed files with 10 additions and 2 deletions

View File

@ -101,8 +101,16 @@ public:
assert(i < size_ && "Array index is out of bounds."); assert(i < size_ && "Array index is out of bounds.");
return reinterpret_cast<const T&>(buffer[i]); return reinterpret_cast<const T&>(buffer[i]);
} }
T& back() { return (*this)[size_ - 1]; } T& back()
const T& back() const { return (*this)[size_ - 1]; } {
assert(size_ > 0 && "Trying to get back of empty array.");
return *(begin() + size_ - 1);
}
const T& back() const
{
assert(size_ > 0 && "Trying to get back of empty array.");
return *(begin() + size_ - 1);
}
T& front() { return (*this)[0]; } T& front() { return (*this)[0]; }
const T& front() const { return (*this)[0]; } const T& front() const { return (*this)[0]; }
T* data() { return reinterpret_cast<T*>(&buffer[0]); } T* data() { return reinterpret_cast<T*>(&buffer[0]); }