From 092e287ba5669f6ed40b721c0bdf2450dae95af8 Mon Sep 17 00:00:00 2001 From: Jonathan Bradley Date: Fri, 1 Sep 2023 10:09:04 -0400 Subject: DynArray<>[] now returns a reference instead of a copy --- src/dynamic-array.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/dynamic-array.hpp') diff --git a/src/dynamic-array.hpp b/src/dynamic-array.hpp index ddcc8b4..1c99b4c 100644 --- a/src/dynamic-array.hpp +++ b/src/dynamic-array.hpp @@ -22,7 +22,7 @@ struct DynArray: DynArrayBase { DynArray(); explicit DynArray(int64_t reserveCount); ~DynArray(); - T operator[](std::size_t index); + T &operator[](std::size_t index); T *GetPtr(); const int64_t Count(); bool Has(const T &val); @@ -54,7 +54,7 @@ template inline DynArray::~DynArray() { DynArrayDestroy(this); } -template inline T DynArray::operator[](std::size_t index) { +template inline T &DynArray::operator[](std::size_t index) { assert(index < this->elementCount && "Invalid DynArray[] index - out of bounds"); assert(index < this->reservedCount && "Invalid DynArray[] index - out of reserved bounds"); return *reinterpret_cast((this->ptr + (sizeof(T) * index))); -- cgit v1.2.3