diff options
Diffstat (limited to 'src/dynamic-array.hpp')
| -rw-r--r-- | src/dynamic-array.hpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/dynamic-array.hpp b/src/dynamic-array.hpp index 876f71d..bcc0d43 100644 --- a/src/dynamic-array.hpp +++ b/src/dynamic-array.hpp @@ -32,6 +32,7 @@ struct DynArray: DynArrayBase { T *GetPtr(); const int64_t Count(); bool Has(const T &val); + int64_t FindFirstIndex(bool fn(const T&)); T& Push(); void Push(const T &val); T Pop(); @@ -135,6 +136,13 @@ template <typename T> inline bool DynArray<T>::Has(const T &val) { return false; } +template <typename T> inline int64_t DynArray<T>::FindFirstIndex(bool Fn(const T&)) { + for (long i = 0; i < this->elementCount; ++i) { + if (Fn(*this)[i]) return i; + } + return -1; +} + template <typename T> inline T &DynArray<T>::Push() { if (this->elementCount + 1 > this->reservedCount) { auto safeReserveCount = this->reservedCount < 2 ? 2 : this->reservedCount; |
