about summary refs log tree commit diff
path: root/absl/types
diff options
context:
space:
mode:
Diffstat (limited to 'absl/types')
-rw-r--r--absl/types/BUILD.bazel2
-rw-r--r--absl/types/span.h7
-rw-r--r--absl/types/span_test.cc1
3 files changed, 10 insertions, 0 deletions
diff --git a/absl/types/BUILD.bazel b/absl/types/BUILD.bazel
index 7841a97d985a..32f690c94c1d 100644
--- a/absl/types/BUILD.bazel
+++ b/absl/types/BUILD.bazel
@@ -136,6 +136,7 @@ cc_test(
         "//absl/base:exception_testing",
         "//absl/container:fixed_array",
         "//absl/container:inlined_vector",
+        "//absl/hash:hash_testing",
         "//absl/strings",
         "@com_google_googletest//:gtest_main",
     ],
@@ -153,6 +154,7 @@ cc_test(
         "//absl/base:exception_testing",
         "//absl/container:fixed_array",
         "//absl/container:inlined_vector",
+        "//absl/hash:hash_testing",
         "//absl/strings",
         "@com_google_googletest//:gtest_main",
     ],
diff --git a/absl/types/span.h b/absl/types/span.h
index 3359ce5093c5..911af0c57a61 100644
--- a/absl/types/span.h
+++ b/absl/types/span.h
@@ -485,6 +485,13 @@ class Span {
                : (base_internal::ThrowStdOutOfRange("pos > size()"), Span());
   }
 
+  // Support for absl::Hash.
+  template <typename H>
+  friend H AbslHashValue(H h, Span v) {
+    return H::combine(H::combine_contiguous(std::move(h), v.data(), v.size()),
+                      v.size());
+  }
+
  private:
   pointer ptr_;
   size_type len_;
diff --git a/absl/types/span_test.cc b/absl/types/span_test.cc
index fbce7e874798..bd739ff2a070 100644
--- a/absl/types/span_test.cc
+++ b/absl/types/span_test.cc
@@ -29,6 +29,7 @@
 #include "absl/base/internal/exception_testing.h"
 #include "absl/container/fixed_array.h"
 #include "absl/container/inlined_vector.h"
+#include "absl/hash/hash_testing.h"
 #include "absl/strings/str_cat.h"
 
 namespace {