about summary refs log tree commit diff
path: root/absl/hash/hash_test.cc
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2020-05-15T15·23-0700
committerAndy Getz <durandal@google.com>2020-05-15T21·57-0400
commit62cf6a70414e15b356ec4f712ca8758133674f28 (patch)
treed517fe8c1bb80458f8dda3e7b77ff7f32cf436d8 /absl/hash/hash_test.cc
parentd118d4bb115387cc52c5338221f2554a940e6d90 (diff)
Export of internal Abseil changes
--
dc36565216b3022abb5a3c92f46fb4079bda869e by Samuel Benzaquen <sbenza@google.com>:

Add support for std::reference_wrapper to absl::Hash.

PiperOrigin-RevId: 311733171
GitOrigin-RevId: dc36565216b3022abb5a3c92f46fb4079bda869e
Change-Id: I74543390446c2b7f6d856935aa36f28539810eef
Diffstat (limited to 'absl/hash/hash_test.cc')
-rw-r--r--absl/hash/hash_test.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/absl/hash/hash_test.cc b/absl/hash/hash_test.cc
index b38d46d47dd3..39ba24a85afb 100644
--- a/absl/hash/hash_test.cc
+++ b/absl/hash/hash_test.cc
@@ -581,6 +581,24 @@ TEST(HashValueTest, Maps) {
       MM{{1, "foo"}, {1, "foo"}, {43, "bar"}}, MM{{1, "foo"}, {43, "baz"}})));
 }
 
+TEST(HashValueTest, ReferenceWrapper) {
+  EXPECT_TRUE(is_hashable<std::reference_wrapper<Private>>::value);
+
+  Private p1{1}, p10{10};
+  EXPECT_TRUE(absl::VerifyTypeImplementsAbslHashCorrectly(std::make_tuple(
+      p1, p10, std::ref(p1), std::ref(p10), std::cref(p1), std::cref(p10))));
+
+  EXPECT_TRUE(is_hashable<std::reference_wrapper<int>>::value);
+  int one = 1, ten = 10;
+  EXPECT_TRUE(absl::VerifyTypeImplementsAbslHashCorrectly(std::make_tuple(
+      one, ten, std::ref(one), std::ref(ten), std::cref(one), std::cref(ten))));
+
+  EXPECT_TRUE(absl::VerifyTypeImplementsAbslHashCorrectly(
+      std::make_tuple(std::tuple<std::reference_wrapper<int>>(std::ref(one)),
+                      std::tuple<std::reference_wrapper<int>>(std::ref(ten)),
+                      std::tuple<int>(one), std::tuple<int>(ten))));
+}
+
 template <typename T, typename = void>
 struct IsHashCallable : std::false_type {};