From 27cd5a90f4c1f34c47cd4e1bd1a616e9b11b10ec Mon Sep 17 00:00:00 2001 From: Shauren Date: Sat, 7 Jan 2023 22:38:21 +0100 Subject: Core/Misc: Replace enable_if overload selection with if constexpr (cherry picked from commit a53e4a57565d3375a978effbbc32d3eed6aac7e3) --- src/common/Containers/Utilities/MapUtils.h | 51 ++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/common/Containers/Utilities/MapUtils.h (limited to 'src/common/Containers/Utilities/MapUtils.h') diff --git a/src/common/Containers/Utilities/MapUtils.h b/src/common/Containers/Utilities/MapUtils.h new file mode 100644 index 00000000000..7cf07243b0a --- /dev/null +++ b/src/common/Containers/Utilities/MapUtils.h @@ -0,0 +1,51 @@ +/* + * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef TRINITYCORE_MAP_UTILS_H +#define TRINITYCORE_MAP_UTILS_H + +#include + +namespace Trinity::Containers +{ +/** + * Returns a pointer to mapped value (or the value itself if map stores pointers) + */ +template +auto MapGetValuePtr(M& map, typename M::key_type const& key) +{ + auto itr = map.find(key); + if constexpr (std::is_pointer_v) + return itr != map.end() ? itr->second : nullptr; + else + return itr != map.end() ? &itr->second : nullptr; +} + +template class M, class... Rest> +void MultimapErasePair(M& multimap, K const& key, V const& value) +{ + auto range = multimap.equal_range(key); + for (auto itr = range.first; itr != range.second;) + { + if (itr->second == value) + itr = multimap.erase(itr); + else + ++itr; + } +} +} +#endif // TRINITYCORE_MAP_UTILS_H -- cgit v1.2.3