summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ryan Prichard <rprichard@google.com> 2024-08-01 18:00:24 -0700
committer Ryan Prichard <rprichard@google.com> 2024-08-06 13:16:49 -0700
commitbb01a640caadc9b85ed522d25480322e48da499e (patch)
tree9dce4c4f36446f9dddb38d1c7ce6362a1a738489
parent9d04fe2c66aff0fea66657f397827ed334ea3b7d (diff)
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<std::string> (i.e. std::hash<std::basic_string<char>> 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
-rw-r--r--libs/math/include/math/TVecHelpers.h19
-rw-r--r--libs/math/include/math/mat2.h2
-rw-r--r--libs/math/include/math/mat3.h2
-rw-r--r--libs/math/include/math/mat4.h2
-rw-r--r--libs/math/include/math/quat.h2
-rw-r--r--libs/math/include/math/vec2.h2
-rw-r--r--libs/math/include/math/vec3.h2
-rw-r--r--libs/math/include/math/vec4.h2
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<template<typename T> class VECTOR, typename T>
- struct hash<VECTOR<T>> {
- static constexpr bool IS_VECTOR =
- std::is_base_of<android::details::TVecUnaryOperators<VECTOR, T>, VECTOR<T>>::value;
-
- typename std::enable_if<IS_VECTOR, size_t>::type
- operator()(const VECTOR<T>& v) const {
- return v.hash();
- }
- };
-}
+#define TVECHELPERS_STD_HASH(VECTOR) \
+ template <typename T> \
+ struct std::hash<VECTOR<T>> { \
+ size_t operator()(const VECTOR<T>& 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<float> 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<float> 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<float> 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<bool> 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<bool> 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<bool> bool4;
// ----------------------------------------------------------------------------------------
} // namespace android
+TVECHELPERS_STD_HASH(android::details::TVec4);
+
#pragma clang diagnostic pop