diff options
Diffstat (limited to 'src/dynamic-array.hpp')
| -rw-r--r-- | src/dynamic-array.hpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/dynamic-array.hpp b/src/dynamic-array.hpp index 645f9c8..95ba967 100644 --- a/src/dynamic-array.hpp +++ b/src/dynamic-array.hpp @@ -31,7 +31,7 @@ struct DynArray: DynArrayBase { T *GetPtr(); const int64_t Count(); bool Has(const T &val); - void Push(); + T& Push(); void Push(const T &val); T Pop(); void Remove(std::size_t index); @@ -127,7 +127,7 @@ template <typename T> inline bool DynArray<T>::Has(const T &val) { return false; } -template <typename T> inline void DynArray<T>::Push() { +template <typename T> inline T &DynArray<T>::Push() { if (this->elementCount + 1 > this->reservedCount) { auto safeReserveCount = this->reservedCount < 2 ? 2 : this->reservedCount; DynArrayReserve(this, int64_t(safeReserveCount * 1.5)); @@ -135,6 +135,7 @@ template <typename T> inline void DynArray<T>::Push() { auto itemPtr = this->ptr + (sizeof(T) * this->elementCount); const auto &targetItem = new(itemPtr) T{}; this->elementCount += 1; + return *reinterpret_cast<T *>(itemPtr); } template <typename T> inline void DynArray<T>::Push(const T &val) { |
