diff options
author | Shauren <shauren.trinity@gmail.com> | 2024-12-31 13:35:35 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2024-12-31 13:35:35 +0100 |
commit | 380dac62fdf88ab11de5547398e4bd9f0855b081 (patch) | |
tree | 2615b9951c7435bf50a6154dfba788ea361bf3fa /src/common/Containers/Utilities/MapUtils.h | |
parent | 5436a6ae6ce28b2cca47ce795d01eeadb37a677d (diff) |
Core/Misc: Add concepts restrictions on container utilities for better compiler error messages
Diffstat (limited to 'src/common/Containers/Utilities/MapUtils.h')
-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;) |