diff options
author | Shauren <shauren.trinity@gmail.com> | 2024-12-31 13:35:35 +0100 |
---|---|---|
committer | Ovahlord <dreadkiller@gmx.de> | 2025-01-01 20:59:00 +0100 |
commit | af13de7f211903586da97ee21e2c9be52ac2b58c (patch) | |
tree | bcc32cdfc111d0d5414ad7c70606fe838720b8dc /src/common/Containers/Utilities | |
parent | bad0764efabada2957e075fd31d6492bc961a0a4 (diff) |
Core/Misc: Add concepts restrictions on container utilities for better compiler error messages
(cherry picked from commit 380dac62fdf88ab11de5547398e4bd9f0855b081)
Diffstat (limited to 'src/common/Containers/Utilities')
-rw-r--r-- | src/common/Containers/Utilities/MapUtils.h | 13 |
1 files changed, 10 insertions, 3 deletions
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 <typename M> +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<class M> +template <Map M> 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 K, class V, template<class, class, class...> class M, class... Rest> -void MultimapErasePair(M<K, V, Rest...>& multimap, K const& key, V const& value) +template <Map M> +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;) |