From 28a0e364bb681d013cd57d68d8ca0f72017fa3c3 Mon Sep 17 00:00:00 2001 From: etkmao Date: Wed, 7 Jun 2023 18:13:23 +0800 Subject: [PATCH] fix(core): fix std hash for xcode15 --- modules/footstone/include/footstone/string_view.h | 9 +++++++++ modules/footstone/src/string_view.cc | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/modules/footstone/include/footstone/string_view.h b/modules/footstone/include/footstone/string_view.h index 27133babedf..2aaa58ef67f 100644 --- a/modules/footstone/include/footstone/string_view.h +++ b/modules/footstone/include/footstone/string_view.h @@ -157,6 +157,15 @@ class string_view final { } // namespace stringview } // namespace footstone +#ifdef __APPLE__ +#if defined(__clang__) && __clang_major__ >= 15 +template<> +struct std::hash { + std::size_t operator()(const footstone::stringview::string_view::u8string& value) const noexcept; +}; +#endif +#endif + template<> struct std::hash { std::size_t operator()(const footstone::stringview::string_view& value) const noexcept; diff --git a/modules/footstone/src/string_view.cc b/modules/footstone/src/string_view.cc index 3cbf23b1b76..757c359f6df 100644 --- a/modules/footstone/src/string_view.cc +++ b/modules/footstone/src/string_view.cc @@ -24,6 +24,15 @@ using string_view = footstone::stringview::string_view; +#ifdef __APPLE__ +#if defined(__clang__) && __clang_major__ >= 15 +std::size_t std::hash::operator()( + const footstone::stringview::string_view::u8string& value) const noexcept { + return std::hash()(std::string(value.begin(), value.end())); +} +#endif +#endif + #if defined(__GLIBC__) && !defined(__cpp_char8_t) std::size_t std::hash::operator()( const string_view::u8string& value) const noexcept {