From b8af5f6a6cf494c17e40654807b3870872002c90 Mon Sep 17 00:00:00 2001 From: Gabriel Busnot Date: Mon, 27 Feb 2023 14:02:41 +0000 Subject: [PATCH] base: stl_hlp::unordered_{map,set} with stl_hlp::hash by default Change-Id: Iad01d7fa6ff6293a2d931ba796666ad3550c6e44 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/67664 Reviewed-by: Daniel Carvalho Tested-by: kokoro Maintainer: Daniel Carvalho --- src/base/stl_helpers/hash_helpers.hh | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/base/stl_helpers/hash_helpers.hh b/src/base/stl_helpers/hash_helpers.hh index f638ea92f2..1432d522bd 100644 --- a/src/base/stl_helpers/hash_helpers.hh +++ b/src/base/stl_helpers/hash_helpers.hh @@ -40,6 +40,11 @@ #include "base/type_traits.hh" +#include +#include +#include +#include + namespace gem5::stl_helpers { @@ -165,6 +170,32 @@ using hash_impl::make_hash_for; using hash_impl::hash_value; using hash_impl::is_hash_enabled; +/* + * Provide unordered_map and unordered_set with stl_helpers::hash functions. + * These aliases enable clean use of stl_helpers::hash as default Hash template + * parameter. The reason for not using an alias is that template type aliases + * with default template arguments do not behave well with template parameter + * deductions in certain situations. One must remember that std::unordered_X + * is not a polymorphic type and as such, gem5::stl_helpers::unordered_X shall + * never be owned as a std::unordered_X. + */ +template< + typename Key, + typename T, + typename Hash = hash, + typename KeyEqual = std::equal_to, + typename Allocator = std::allocator< std::pair >> +struct unordered_map: std::unordered_map +{}; + +template< + typename Key, + typename Hash = hash, + typename KeyEqual = std::equal_to, + typename Allocator = std::allocator> +struct unordered_set: std::unordered_set +{}; + } // namespace gem5::stl_helpers #endif // BASE_STL_HELPERS_HASH_HELPERS_HH