summaryrefslogtreecommitdiff
path: root/src/dynamic-array.hpp
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2023-12-23 11:33:55 -0500
committerJonathan Bradley <jcb@pikum.xyz>2023-12-23 11:33:55 -0500
commita527dd1b773f14df140d3ac6a167339d7dc39e33 (patch)
tree4da92bf0e54a5f43bff499fdd2dae156ab35f885 /src/dynamic-array.hpp
parent365eb04eebf4e5fc6d1d47d55cd541eedb47f64c (diff)
FindFirstIndex for DynArray and PkeArray
Diffstat (limited to 'src/dynamic-array.hpp')
-rw-r--r--src/dynamic-array.hpp8
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;