File indexing completed on 2025-01-18 09:27:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #ifndef ABSL_HASH_INTERNAL_HASH_TEST_H_
0019 #define ABSL_HASH_INTERNAL_HASH_TEST_H_
0020
0021 #include <type_traits>
0022 #include <utility>
0023
0024 #include "absl/base/config.h"
0025 #include "absl/hash/hash.h"
0026
0027 namespace absl {
0028 ABSL_NAMESPACE_BEGIN
0029 namespace hash_test_internal {
0030
0031
0032
0033
0034
0035 template <typename T>
0036 class TypeErasedValue {
0037 public:
0038 TypeErasedValue() = default;
0039 TypeErasedValue(const TypeErasedValue&) = default;
0040 TypeErasedValue(TypeErasedValue&&) = default;
0041 explicit TypeErasedValue(const T& n) : n_(n) {}
0042
0043 template <typename H>
0044 friend H AbslHashValue(H hash_state, const TypeErasedValue& v) {
0045 v.HashValue(absl::HashState::Create(&hash_state));
0046 return hash_state;
0047 }
0048
0049 void HashValue(absl::HashState state) const {
0050 absl::HashState::combine(std::move(state), n_);
0051 }
0052
0053 bool operator==(const TypeErasedValue& rhs) const { return n_ == rhs.n_; }
0054 bool operator!=(const TypeErasedValue& rhs) const { return !(*this == rhs); }
0055
0056 private:
0057 T n_;
0058 };
0059
0060
0061
0062 template <typename T>
0063 class TypeErasedContainer : public TypeErasedValue<T> {
0064 public:
0065 using value_type = typename T::value_type;
0066 TypeErasedContainer() = default;
0067 TypeErasedContainer(const TypeErasedContainer&) = default;
0068 TypeErasedContainer(TypeErasedContainer&&) = default;
0069 explicit TypeErasedContainer(const T& n) : TypeErasedValue<T>(n) {}
0070 TypeErasedContainer(std::initializer_list<value_type> init_list)
0071 : TypeErasedContainer(T(init_list.begin(), init_list.end())) {}
0072
0073
0074 explicit TypeErasedContainer(const value_type& v)
0075 : TypeErasedContainer(T(&v, &v + 1)) {}
0076 };
0077
0078
0079
0080 template <typename T>
0081 using is_hashable = std::is_default_constructible<absl::Hash<T>>;
0082
0083 }
0084 ABSL_NAMESPACE_END
0085 }
0086
0087 #endif