diff options
author | Abseil Team <absl-team@google.com> | 2019-01-30T18·59-0800 |
---|---|---|
committer | Ashley Hedberg <ahedberg@google.com> | 2019-01-30T19·24-0500 |
commit | a4cb1c8ba61531a63f9d309eea01ac1d43d8371d (patch) | |
tree | 4cd407a27c50ef86e2644af93f117cf5eb2b7bd3 /absl/types | |
parent | 540e2537b92cd4abfae6ceddfe24304345461f32 (diff) |
Export of internal Abseil changes.
-- 6fdf24a197b964f9bacbebd0ceca305aef1654fc by Shaindel Schwartz <shaindel@google.com>: Internal change PiperOrigin-RevId: 231627312 -- 65f7faf52bff01384171efb85fee159378dedf70 by CJ Johnson <johnsoncj@google.com>: Relocates the definitions of the InputIterator-accepting parts of the InlinedVector API into the top-level. The removed functions had no other callers so there was no reason to keep the layer of indirection in the form of the function call. PiperOrigin-RevId: 231527459 -- 30e105b749b5ecc50fdaf26c7da589617efce425 by CJ Johnson <johnsoncj@google.com>: Relocates closing brace for absl namespace in InlinedVector to the correct end location PiperOrigin-RevId: 231477871 -- 063c1e8b9d1f032662c46d574e20ecc357b87d0c by Eric Fiselier <ericwf@google.com>: Cleanup std::hash probing metafunctions. Previously there were two different ways to probe for std::hash. One in hash.h and another in type_traits.h, and they were both implemented differently, and neither correctly worked around bad STL implementations. This patch unifies the implementations into a single IsHashable trait. It also: * Correctly checks for old libc++ versions where this won't work. * Avoids undefined behavior which resulted from calling std::is_constructible incomplete types. * Unifies the feature test macro used in the headers and the tests. Additionally it also slightly changes the behavior of when absl::variant is hashable. Previously we disable hashing when std::hash<T>()(key) was formed but when std::hash<T> couldn't be destructed. This seems wrong. If a user provides a evil specialization of std::hash, then it's OK for variant's hash to blow up. PiperOrigin-RevId: 231468345 -- 05d75dd4b07c893de9b104731644d0d207b01253 by Abseil Team <absl-team@google.com>: Import of CCTZ from GitHub. PiperOrigin-RevId: 231397518 -- a0ee9032f9e04039f3410ed17fcf45ae1a3868f5 by CJ Johnson <johnsoncj@google.com>: Remove unused EnableIfAtLeastInputIterator from InlinedVector PiperOrigin-RevId: 231348903 -- 4dcd4e9a6780a81d7a6974c7bf22a037e6482b49 by Abseil Team <absl-team@google.com>: Remove unnecessary register keyword from absl/base/internal/endian.h. PiperOrigin-RevId: 231316570 -- c8584836caa3a10f90a8604a85d4b831310b72ee by Abseil Team <absl-team@google.com>: Fix hashtablez_sampler compilation on older Android NDK builds PiperOrigin-RevId: 231283542 GitOrigin-RevId: 6fdf24a197b964f9bacbebd0ceca305aef1654fc Change-Id: I185b12fb8347e3ad0ffcb2cbb83a53450e5eb938
Diffstat (limited to 'absl/types')
-rw-r--r-- | absl/types/internal/variant.h | 3 | ||||
-rw-r--r-- | absl/types/optional.h | 1 | ||||
-rw-r--r-- | absl/types/optional_test.cc | 21 | ||||
-rw-r--r-- | absl/types/variant_test.cc | 35 |
4 files changed, 25 insertions, 35 deletions
diff --git a/absl/types/internal/variant.h b/absl/types/internal/variant.h index 477e5895ed73..a0ab1e8fdb26 100644 --- a/absl/types/internal/variant.h +++ b/absl/types/internal/variant.h @@ -1605,11 +1605,12 @@ struct VariantHashVisitor { template <typename Variant, typename... Ts> struct VariantHashBase<Variant, absl::enable_if_t<absl::conjunction< - type_traits_internal::IsHashEnabled<Ts>...>::value>, + type_traits_internal::IsHashable<Ts>...>::value>, Ts...> { using argument_type = Variant; using result_type = size_t; size_t operator()(const Variant& var) const { + type_traits_internal::AssertHashEnabled<Ts...>(); if (var.valueless_by_exception()) { return 239799884; } diff --git a/absl/types/optional.h b/absl/types/optional.h index 7677fe52c0e5..fd185f353f3e 100644 --- a/absl/types/optional.h +++ b/absl/types/optional.h @@ -467,6 +467,7 @@ struct optional_hash_base<T, decltype(std::hash<absl::remove_const_t<T> >()( using argument_type = absl::optional<T>; using result_type = size_t; size_t operator()(const absl::optional<T>& opt) const { + absl::type_traits_internal::AssertHashEnabled<absl::remove_const_t<T>>(); if (opt) { return std::hash<absl::remove_const_t<T> >()(*opt); } else { diff --git a/absl/types/optional_test.cc b/absl/types/optional_test.cc index fc4f00a4f52f..bedf5b0e043e 100644 --- a/absl/types/optional_test.cc +++ b/absl/types/optional_test.cc @@ -1504,18 +1504,19 @@ TEST(optionalTest, Hash) { static_assert(is_hash_enabled_for<absl::optional<int>>::value, ""); static_assert(is_hash_enabled_for<absl::optional<Hashable>>::value, ""); + static_assert( + absl::type_traits_internal::IsHashable<absl::optional<int>>::value, ""); + static_assert( + absl::type_traits_internal::IsHashable<absl::optional<Hashable>>::value, + ""); + absl::type_traits_internal::AssertHashEnabled<absl::optional<int>>(); + absl::type_traits_internal::AssertHashEnabled<absl::optional<Hashable>>(); -#if defined(_MSC_VER) || (defined(_LIBCPP_VERSION) && \ - _LIBCPP_VERSION < 4000 && _LIBCPP_STD_VER > 11) - // For MSVC and libc++ (< 4.0 and c++14), std::hash primary template has a - // static_assert to catch any user-defined type that doesn't provide a hash - // specialization. So instantiating std::hash<absl::optional<T>> will result - // in a hard error which is not SFINAE friendly. -#define ABSL_STD_HASH_NOT_SFINAE_FRIENDLY 1 -#endif - -#ifndef ABSL_STD_HASH_NOT_SFINAE_FRIENDLY +#if ABSL_META_INTERNAL_STD_HASH_SFINAE_FRIENDLY_ static_assert(!is_hash_enabled_for<absl::optional<NonHashable>>::value, ""); + static_assert(!absl::type_traits_internal::IsHashable< + absl::optional<NonHashable>>::value, + ""); #endif // libstdc++ std::optional is missing remove_const_t, i.e. it's using diff --git a/absl/types/variant_test.cc b/absl/types/variant_test.cc index 80e8467e1f14..463d775a85fe 100644 --- a/absl/types/variant_test.cc +++ b/absl/types/variant_test.cc @@ -1977,29 +1977,17 @@ TEST(VariantTest, MonostateHash) { } TEST(VariantTest, Hash) { - static_assert(type_traits_internal::IsHashEnabled<variant<int>>::value, ""); - static_assert(type_traits_internal::IsHashEnabled<variant<Hashable>>::value, + static_assert(type_traits_internal::IsHashable<variant<int>>::value, ""); + static_assert(type_traits_internal::IsHashable<variant<Hashable>>::value, ""); + static_assert(type_traits_internal::IsHashable<variant<int, Hashable>>::value, ""); - static_assert( - type_traits_internal::IsHashEnabled<variant<int, Hashable>>::value, ""); - -#if defined(_MSC_VER) || \ - (defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 4000 && \ - _LIBCPP_STD_VER > 11) || \ - defined(__APPLE__) - // For MSVC and libc++ (< 4.0 and c++14), std::hash primary template has a - // static_assert to catch any user-defined type T that doesn't provide a hash - // specialization. So instantiating std::hash<variant<T>> will result - // in a hard error which is not SFINAE friendly. -#define ABSL_STD_HASH_NOT_SFINAE_FRIENDLY 1 -#endif -#ifndef ABSL_STD_HASH_NOT_SFINAE_FRIENDLY - static_assert( - !type_traits_internal::IsHashEnabled<variant<NonHashable>>::value, ""); - static_assert(!type_traits_internal::IsHashEnabled< - variant<Hashable, NonHashable>>::value, +#if ABSL_META_INTERNAL_STD_HASH_SFINAE_FRIENDLY_ + static_assert(!type_traits_internal::IsHashable<variant<NonHashable>>::value, ""); + static_assert( + !type_traits_internal::IsHashable<variant<Hashable, NonHashable>>::value, + ""); #endif // MSVC std::hash<std::variant> does not use the index, thus produce the same @@ -2023,11 +2011,10 @@ TEST(VariantTest, Hash) { EXPECT_GT(hashcodes.size(), 90); // test const-qualified + static_assert(type_traits_internal::IsHashable<variant<const int>>::value, + ""); static_assert( - type_traits_internal::IsHashEnabled<variant<const int>>::value, ""); - static_assert( - type_traits_internal::IsHashEnabled<variant<const Hashable>>::value, - ""); + type_traits_internal::IsHashable<variant<const Hashable>>::value, ""); std::hash<absl::variant<const int>> c_hash; for (int i = 0; i < 100; ++i) { EXPECT_EQ(hash(i), c_hash(i)); |