summaryrefslogtreecommitdiff
path: root/src/dynamic-array.hpp
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2023-09-01 10:09:04 -0400
committerJonathan Bradley <jcb@pikum.xyz>2023-09-06 17:24:27 -0400
commit092e287ba5669f6ed40b721c0bdf2450dae95af8 (patch)
tree77bf89e4123021bdfa09d6198241446691cf4100 /src/dynamic-array.hpp
parent8941504bc66176540f71510f393aeabe382594cb (diff)
DynArray<>[] now returns a reference instead of a copy
Diffstat (limited to 'src/dynamic-array.hpp')
-rw-r--r--src/dynamic-array.hpp4
1 files changed, 2 insertions, 2 deletions
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 <typename T> inline DynArray<T>::~DynArray() {
DynArrayDestroy(this);
}
-template <typename T> inline T DynArray<T>::operator[](std::size_t index) {
+template <typename T> inline T &DynArray<T>::operator[](std::size_t index) {
assert(index < this->elementCount && "Invalid DynArray<T>[] index - out of bounds");
assert(index < this->reservedCount && "Invalid DynArray<T>[] index - out of reserved bounds");
return *reinterpret_cast<T *>((this->ptr + (sizeof(T) * index)));