From bb01a640caadc9b85ed522d25480322e48da499e Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Thu, 1 Aug 2024 18:00:24 -0700 Subject: libmath: use TVECHELPERS_STD_HASH macro for std::hash Upstream Clang has enabled the -frelaxed-template-template-args option by default (llvm.org/PR89807) and deprecated -fno-relaxed-template-template-args. With the new relaxed template-template behavior, libmath's partial specialization is also a candidate for std::hash (i.e. std::hash> where VECTOR is std::basic_string and T is char). To avoid the ambiguity, use a C macro to define a partial specialization for each of TVec{2,3,4}, TMat{22,33,44}, and TQuaternion. Bug: http://b/341084395 Test: atest hashcombine_test Change-Id: I0837e0de327914f94a1dd13a49b470fc78e164b1 --- libs/math/include/math/TVecHelpers.h | 19 +++++++------------ libs/math/include/math/mat2.h | 2 ++ libs/math/include/math/mat3.h | 2 ++ libs/math/include/math/mat4.h | 2 ++ libs/math/include/math/quat.h | 2 ++ libs/math/include/math/vec2.h | 2 ++ libs/math/include/math/vec3.h | 2 ++ libs/math/include/math/vec4.h | 2 ++ 8 files changed, 21 insertions(+), 12 deletions(-) diff --git a/libs/math/include/math/TVecHelpers.h b/libs/math/include/math/TVecHelpers.h index 0dac662e97..7278d2d3e1 100644 --- a/libs/math/include/math/TVecHelpers.h +++ b/libs/math/include/math/TVecHelpers.h @@ -620,15 +620,10 @@ public: } // namespace details } // namespace android -namespace std { - template class VECTOR, typename T> - struct hash> { - static constexpr bool IS_VECTOR = - std::is_base_of, VECTOR>::value; - - typename std::enable_if::type - operator()(const VECTOR& v) const { - return v.hash(); - } - }; -} +#define TVECHELPERS_STD_HASH(VECTOR) \ + template \ + struct std::hash> { \ + size_t operator()(const VECTOR& v) const { \ + return v.hash(); \ + } \ + } diff --git a/libs/math/include/math/mat2.h b/libs/math/include/math/mat2.h index 3e6cd4c794..24c2bad420 100644 --- a/libs/math/include/math/mat2.h +++ b/libs/math/include/math/mat2.h @@ -373,5 +373,7 @@ typedef details::TMat22 mat2f; // ---------------------------------------------------------------------------------------- } // namespace android +TVECHELPERS_STD_HASH(android::details::TMat22); + #undef PURE #undef CONSTEXPR diff --git a/libs/math/include/math/mat3.h b/libs/math/include/math/mat3.h index 5c8a9b2573..4647a60917 100644 --- a/libs/math/include/math/mat3.h +++ b/libs/math/include/math/mat3.h @@ -436,5 +436,7 @@ typedef details::TMat33 mat3f; // ---------------------------------------------------------------------------------------- } // namespace android +TVECHELPERS_STD_HASH(android::details::TMat33); + #undef PURE #undef CONSTEXPR diff --git a/libs/math/include/math/mat4.h b/libs/math/include/math/mat4.h index c630d972b2..c9e118ab34 100644 --- a/libs/math/include/math/mat4.h +++ b/libs/math/include/math/mat4.h @@ -590,5 +590,7 @@ typedef details::TMat44 mat4f; // ---------------------------------------------------------------------------------------- } // namespace android +TVECHELPERS_STD_HASH(android::details::TMat44); + #undef PURE #undef CONSTEXPR diff --git a/libs/math/include/math/quat.h b/libs/math/include/math/quat.h index 07573c5ecf..43c8038cc1 100644 --- a/libs/math/include/math/quat.h +++ b/libs/math/include/math/quat.h @@ -187,6 +187,8 @@ constexpr inline quatd operator"" _kd(unsigned long long v) { // NOLINT // ---------------------------------------------------------------------------------------- } // namespace android +TVECHELPERS_STD_HASH(android::details::TQuaternion); + #pragma clang diagnostic pop #undef PURE diff --git a/libs/math/include/math/vec2.h b/libs/math/include/math/vec2.h index e0adb7f6cc..909c77eb28 100644 --- a/libs/math/include/math/vec2.h +++ b/libs/math/include/math/vec2.h @@ -122,4 +122,6 @@ typedef details::TVec2 bool2; // ---------------------------------------------------------------------------------------- } // namespace android +TVECHELPERS_STD_HASH(android::details::TVec2); + #pragma clang diagnostic pop diff --git a/libs/math/include/math/vec3.h b/libs/math/include/math/vec3.h index 21fb684efc..ff2b3e4f54 100644 --- a/libs/math/include/math/vec3.h +++ b/libs/math/include/math/vec3.h @@ -128,4 +128,6 @@ typedef details::TVec3 bool3; // ---------------------------------------------------------------------------------------- } // namespace android +TVECHELPERS_STD_HASH(android::details::TVec3); + #pragma clang diagnostic pop diff --git a/libs/math/include/math/vec4.h b/libs/math/include/math/vec4.h index 1e279fe3f2..16509c91a1 100644 --- a/libs/math/include/math/vec4.h +++ b/libs/math/include/math/vec4.h @@ -125,4 +125,6 @@ typedef details::TVec4 bool4; // ---------------------------------------------------------------------------------------- } // namespace android +TVECHELPERS_STD_HASH(android::details::TVec4); + #pragma clang diagnostic pop -- cgit v1.2.3-59-g8ed1b