From 27e7a99106e7796057ca74cd4edfac28b09f6554 Mon Sep 17 00:00:00 2001 From: Shauren Date: Sun, 23 Feb 2025 11:33:53 +0100 Subject: Core/Utils: Added map key/value utility projections for std::ranges algorithms (cherry picked from commit 67418a1aeee9035234d304b5e9653b832488dd66) --- src/common/Containers/FlatSet.h | 2 +- src/common/Containers/Utilities/MapUtils.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'src/common/Containers') diff --git a/src/common/Containers/FlatSet.h b/src/common/Containers/FlatSet.h index 5602ba17254..2a94282794a 100644 --- a/src/common/Containers/FlatSet.h +++ b/src/common/Containers/FlatSet.h @@ -70,7 +70,7 @@ public: return { _storage.emplace(itr, std::move(newElement)), true }; } - std::pair insert(Key const& key) { return emplace(key); } + std::pair insert(Key const& key) { return this->emplace(key); } std::size_t erase(Key const& key) { diff --git a/src/common/Containers/Utilities/MapUtils.h b/src/common/Containers/Utilities/MapUtils.h index cb76a9d0579..e4cf6309bef 100644 --- a/src/common/Containers/Utilities/MapUtils.h +++ b/src/common/Containers/Utilities/MapUtils.h @@ -65,5 +65,16 @@ void MultimapErasePair(M& multimap, typename M::key_type const& key, typename M: ++itr; } } + +/** + * Map key projection for various std::ranges algorithms + */ +inline constexpr auto MapKey = [](Pair&& pair) constexpr -> decltype(auto) { return (std::forward(pair).first); /*Parentheses required for decltype(auto) to deduce a reference*/ }; + +/** + * Map value projection for various std::ranges algorithms + */ +inline constexpr auto MapValue = [](Pair&& pair) constexpr -> decltype(auto) { return (std::forward(pair).second); /*Parentheses required for decltype(auto) to deduce a reference*/ +}; } #endif // TRINITYCORE_MAP_UTILS_H -- cgit v1.2.3