summaryrefslogtreecommitdiff
path: root/absl/hash/internal
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2023-03-24 11:49:57 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2023-03-24 11:50:58 -0700
commit700e786e607788fb514a9021375191e47484fcb1 (patch)
tree15c6dc44e75f4b4a0c8b046b0fc417165d8764c7 /absl/hash/internal
parent7b9f660fc35321c53f421e8e8948fa6e2042a4e1 (diff)
Hash support for std::wstring_view/u16string_view/u32string_view
PiperOrigin-RevId: 519200954 Change-Id: I349023cacab0ac4cbefb8505efd29a5eda1e9067
Diffstat (limited to 'absl/hash/internal')
-rw-r--r--absl/hash/internal/hash.h22
1 files changed, 21 insertions, 1 deletions
diff --git a/absl/hash/internal/hash.h b/absl/hash/internal/hash.h
index a22a537b..7e534d85 100644
--- a/absl/hash/internal/hash.h
+++ b/absl/hash/internal/hash.h
@@ -56,6 +56,10 @@
#include "absl/types/variant.h"
#include "absl/utility/utility.h"
+#ifdef ABSL_HAVE_STD_STRING_VIEW
+#include <string_view>
+#endif
+
namespace absl {
ABSL_NAMESPACE_BEGIN
@@ -518,7 +522,8 @@ H AbslHashValue(H hash_state, const std::shared_ptr<T>& ptr) {
// - `absl::Cord`
// - `std::string` (and std::basic_string<T, std::char_traits<T>, A> for
// any allocator A and any T in {char, wchar_t, char16_t, char32_t})
-// - `absl::string_view` and `std::string_view`
+// - `absl::string_view`, `std::string_view`, `std::wstring_view`,
+// `std::u16string_view`, and `std::u32_string_view`.
//
// For simplicity, we currently support only strings built on `char`, `wchar_t`,
// `char16_t`, or `char32_t`. This support may be broadened, if necessary, but
@@ -544,6 +549,21 @@ H AbslHashValue(
str.size());
}
+#ifdef ABSL_HAVE_STD_STRING_VIEW
+
+// Support std::wstring_view, std::u16string_view and std::u32string_view.
+template <typename Char, typename H,
+ typename = absl::enable_if_t<std::is_same<Char, wchar_t>::value ||
+ std::is_same<Char, char16_t>::value ||
+ std::is_same<Char, char32_t>::value>>
+H AbslHashValue(H hash_state, std::basic_string_view<Char> str) {
+ return H::combine(
+ H::combine_contiguous(std::move(hash_state), str.data(), str.size()),
+ str.size());
+}
+
+#endif // ABSL_HAVE_STD_STRING_VIEW
+
// -----------------------------------------------------------------------------
// AbslHashValue for Sequence Containers
// -----------------------------------------------------------------------------