From c0f8e8535a025b29557385c95338b642fbda39e8 Mon Sep 17 00:00:00 2001 From: Treeston Date: Fri, 19 Jul 2019 20:37:22 +0200 Subject: build fix after d1dc0e2 --- src/common/Utilities/Containers.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/common/Utilities/Containers.h') diff --git a/src/common/Utilities/Containers.h b/src/common/Utilities/Containers.h index ba929bc2a84..0454b8d4aad 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 @@ -241,6 +242,34 @@ namespace Trinity ++itr; } } + + template + std::enable_if_t().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 + std::enable_if_t().begin())>, void> EraseIf(Container& c, Predicate p) + { + for (auto it = c.begin(); it != c.end();) + { + if (p(*it)) + it = c.erase(it); + else + ++it; + } + } } //! namespace Containers } -- cgit v1.2.3