[libcxx-commits] [PATCH] D92325: Add std::hash<char8_t> specialization if char8_t is enabled
Yuriy Chernyshov via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Nov 30 07:45:19 PST 2020
georgthegreat created this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.
georgthegreat requested review of this revision.
This diff is related to D92212 <https://reviews.llvm.org/D92212/> as it is not clear which macro should be tested to enabled char8_t support.
I hope @ldionne will make a decision.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D92325
Files:
libcxx/include/functional
libcxx/include/utility
libcxx/test/libcxx/extensions/hash/specializations.pass.cpp
Index: libcxx/test/libcxx/extensions/hash/specializations.pass.cpp
===================================================================
--- libcxx/test/libcxx/extensions/hash/specializations.pass.cpp
+++ libcxx/test/libcxx/extensions/hash/specializations.pass.cpp
@@ -23,6 +23,9 @@
assert(__gnu_cxx::hash<char>()(42) == 42);
assert(__gnu_cxx::hash<signed char>()(42) == 42);
assert(__gnu_cxx::hash<unsigned char>()(42) == 42);
+ #ifdef __cpp_lib_char8_t
+ assert(__gnu_cxx::hash<char8_t>()(42) == 42);
+ #endif
assert(__gnu_cxx::hash<short>()(42) == 42);
assert(__gnu_cxx::hash<unsigned short>()(42) == 42);
assert(__gnu_cxx::hash<int>()(42) == 42);
Index: libcxx/include/utility
===================================================================
--- libcxx/include/utility
+++ libcxx/include/utility
@@ -1364,6 +1364,16 @@
size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
};
+#ifdef __cpp_char8_t
+template <>
+struct _LIBCPP_TEMPLATE_VIS hash<char8_t>
+ : public unary_function<char8_t, size_t>
+{
+ _LIBCPP_INLINE_VISIBILITY
+ size_t operator()(char8_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
+};
+#endif // __cpp_char8_t
+
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
template <>
Index: libcxx/include/functional
===================================================================
--- libcxx/include/functional
+++ libcxx/include/functional
@@ -470,6 +470,7 @@
template <> struct hash<char>;
template <> struct hash<signed char>;
template <> struct hash<unsigned char>;
+template <> struct hash<char8_t>; // since C++20
template <> struct hash<char16_t>;
template <> struct hash<char32_t>;
template <> struct hash<wchar_t>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92325.308368.patch
Type: text/x-patch
Size: 1739 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20201130/897d6bff/attachment.bin>
More information about the libcxx-commits
mailing list