From af13de7f211903586da97ee21e2c9be52ac2b58c Mon Sep 17 00:00:00 2001 From: Shauren Date: Tue, 31 Dec 2024 13:35:35 +0100 Subject: Core/Misc: Add concepts restrictions on container utilities for better compiler error messages (cherry picked from commit 380dac62fdf88ab11de5547398e4bd9f0855b081) --- src/common/Containers/Utilities/MapUtils.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/common/Containers/Utilities/MapUtils.h') diff --git a/src/common/Containers/Utilities/MapUtils.h b/src/common/Containers/Utilities/MapUtils.h index 910f16022a6..88f25c1d28a 100644 --- a/src/common/Containers/Utilities/MapUtils.h +++ b/src/common/Containers/Utilities/MapUtils.h @@ -23,10 +23,17 @@ namespace Trinity::Containers { +template +concept Map = requires (M) +{ + typename M::key_type; + typename M::mapped_type; +}; + /** * Returns a pointer to mapped value (or the value itself if map stores pointers) */ -template +template inline auto MapGetValuePtr(M& map, typename M::key_type const& key) { using mapped_type = typename M::mapped_type; @@ -46,8 +53,8 @@ inline auto MapGetValuePtr(M& map, typename M::key_type const& key) return itr != map.end() ? std::addressof(itr->second) : nullptr; // value } -template class M, class... Rest> -void MultimapErasePair(M& multimap, K const& key, V const& value) +template +void MultimapErasePair(M& multimap, typename M::key_type const& key, typename M::mapped_type const& value) { auto range = multimap.equal_range(key); for (auto itr = range.first; itr != range.second;) -- cgit v1.2.3