diff --git a/include/marl/containers.h b/include/marl/containers.h index 337ab3d..2eaee0b 100644 --- a/include/marl/containers.h +++ b/include/marl/containers.h @@ -62,8 +62,12 @@ class vector { inline void pop_back(); inline T& front(); inline T& back(); + inline const T& front() const; + inline const T& back() const; inline T* begin(); inline T* end(); + inline const T* begin() const; + inline const T* end() const; inline T& operator[](size_t i); inline const T& operator[](size_t i) const; inline size_t size() const; @@ -186,6 +190,18 @@ T& vector::back() { return reinterpret_cast(elements)[count - 1]; } +template +const T& vector::front() const { + MARL_ASSERT(count > 0, "front() called on empty vector"); + return reinterpret_cast(elements)[0]; +} + +template +const T& vector::back() const { + MARL_ASSERT(count > 0, "back() called on empty vector"); + return reinterpret_cast(elements)[count - 1]; +} + template T* vector::begin() { return reinterpret_cast(elements); @@ -196,6 +212,16 @@ T* vector::end() { return reinterpret_cast(elements) + count; } +template +const T* vector::begin() const { + return reinterpret_cast(elements); +} + +template +const T* vector::end() const { + return reinterpret_cast(elements) + count; +} + template T& vector::operator[](size_t i) { MARL_ASSERT(i < count, "index %d exceeds vector size %d", int(i), int(count));