aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/Utilities/Containers.h29
-rw-r--r--src/common/Utilities/advstd.h3
-rw-r--r--src/server/game/Entities/Player/Player.cpp4
3 files changed, 34 insertions, 2 deletions
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 <algorithm>
@@ -241,6 +242,34 @@ namespace Trinity
++itr;
}
}
+
+ 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;
+ }
+ }
}
//! namespace Containers
}
diff --git a/src/common/Utilities/advstd.h b/src/common/Utilities/advstd.h
index df962a0bbcd..5606b84cfa2 100644
--- a/src/common/Utilities/advstd.h
+++ b/src/common/Utilities/advstd.h
@@ -79,6 +79,9 @@ namespace advstd
// C++17 std::is_arithmetic_v
forward_1v(is_arithmetic, bool);
+ // C++17 std::is_move_assignable_v
+ forward_1v(is_move_assignable, bool);
+
#undef forward_1v
#undef forward_2v
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index afa99e28032..703f8e29beb 100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -24562,7 +24562,7 @@ void Player::RestoreBaseRune(uint8 index)
if (storedAura->GetSpellInfo()->HasAttribute(SPELL_ATTR0_PASSIVE))
{
- // Don't drop passive talents providing rune convertion
+ // Don't drop passive talents providing rune conversion
if (storedAura->GetAuraType() == SPELL_AURA_CONVERT_RUNE)
removeList.push_back(storedAura);
return true;
@@ -24572,7 +24572,7 @@ void Player::RestoreBaseRune(uint8 index)
return false;
};
- auras.erase(std::remove_if(auras.begin(), auras.end(), criteria), auras.end());
+ Trinity::Containers::EraseIf(auras, criteria);
if (!auras.empty())
return;