From cc5951cfc302a02645b9d066ce50f95f31bbe6a6 Mon Sep 17 00:00:00 2001 From: andrey Date: Thu, 9 Sep 2021 17:38:28 +0300 Subject: [PATCH] PIVector getRange removeWhere --- libs/main/containers/pivector.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libs/main/containers/pivector.h b/libs/main/containers/pivector.h index 97f99453..d62989a0 100644 --- a/libs/main/containers/pivector.h +++ b/libs/main/containers/pivector.h @@ -283,6 +283,12 @@ public: inline T * data(size_t index = 0) {return &(piv_data[index]);} inline const T * data(size_t index = 0) const {return &(piv_data[index]);} + PIVector getRange(size_t index, size_t count) const { + if (index >= piv_size || count == 0) return PIVector(); + if (index + count > piv_size) count = piv_size - index; + return PIVector(&(piv_data[index]), count); + } + template::value , int>::type = 0> @@ -462,7 +468,6 @@ public: } return *this; } - inline PIVector & removeAll(const T & e) { for (ssize_t i = 0; i < ssize_t(piv_size); ++i) { if (piv_data[i] == e) { @@ -472,6 +477,15 @@ public: } return *this; } + inline PIVector & removeWhere(std::function test) { + for (ssize_t i = 0; i < ssize_t(piv_size); ++i) { + if (test(piv_data[i])) { + remove(i); + --i; + } + } + return *this; + } inline PIVector & push_back(const T & e) { alloc(piv_size + 1);