aboutsummaryrefslogtreecommitdiff
path: root/src/common/Utilities/Containers.h
diff options
context:
space:
mode:
authorTreeston <treeston.mmoc@gmail.com>2019-07-19 20:37:22 +0200
committerShauren <shauren.trinity@gmail.com>2021-12-16 22:16:07 +0100
commit611ddfee3c36e6b9dc700337c3547137ff7c6752 (patch)
treec5e6b2bb7f5bc76ad5df09a072e755d55ba2041b /src/common/Utilities/Containers.h
parente94dca132b4a505f3cc4583bd63879148ad51ca3 (diff)
build fix after d1dc0e2
(cherry picked from commit c0f8e8535a025b29557385c95338b642fbda39e8)
Diffstat (limited to 'src/common/Utilities/Containers.h')
-rw-r--r--src/common/Utilities/Containers.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/common/Utilities/Containers.h b/src/common/Utilities/Containers.h
index 01ffac76769..4d376a8eb38 100644
--- a/src/common/Utilities/Containers.h
+++ b/src/common/Utilities/Containers.h
@@ -18,6 +18,7 @@
#ifndef TRINITY_CONTAINERS_H
#define TRINITY_CONTAINERS_H
+#include "advstd.h"
#include "Define.h"
#include "Random.h"
#include <algorithm>
@@ -273,6 +274,34 @@ namespace Trinity
}
}
+ template <typename Container, typename Predicate>
+ std::enable_if_t<advstd::is_move_assignable_v<decltype(*std::declval<Container>().begin())>, void> EraseIf(Container& c, Predicate p)
+ {
+ auto wpos = c.begin();
+ for (auto rpos = c.begin(), end = c.end(); rpos != end; ++rpos)
+ {
+ if (!p(*rpos))
+ {
+ if (rpos != wpos)
+ std::swap(*rpos, *wpos);
+ ++wpos;
+ }
+ }
+ c.erase(wpos, c.end());
+ }
+
+ template <typename Container, typename Predicate>
+ std::enable_if_t<!advstd::is_move_assignable_v<decltype(*std::declval<Container>().begin())>, void> EraseIf(Container& c, Predicate p)
+ {
+ for (auto it = c.begin(); it != c.end();)
+ {
+ if (p(*it))
+ it = c.erase(it);
+ else
+ ++it;
+ }
+ }
+
/**
* Returns a mutable reference to element at index i
* Will resize vector if neccessary to ensure element at i can be safely written