Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bb01a640 authored by Ryan Prichard's avatar Ryan Prichard
Browse files

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
parent 9d04fe2c
Loading
Loading
Loading
Loading
+7 −12
Original line number Diff line number Diff line
@@ -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();                          \
        }                                             \
    }
+2 −0
Original line number Diff line number Diff line
@@ -373,5 +373,7 @@ typedef details::TMat22<float> mat2f;
// ----------------------------------------------------------------------------------------
}  // namespace android

TVECHELPERS_STD_HASH(android::details::TMat22);

#undef PURE
#undef CONSTEXPR
+2 −0
Original line number Diff line number Diff line
@@ -436,5 +436,7 @@ typedef details::TMat33<float> mat3f;
// ----------------------------------------------------------------------------------------
}  // namespace android

TVECHELPERS_STD_HASH(android::details::TMat33);

#undef PURE
#undef CONSTEXPR
+2 −0
Original line number Diff line number Diff line
@@ -590,5 +590,7 @@ typedef details::TMat44<float> mat4f;
// ----------------------------------------------------------------------------------------
}  // namespace android

TVECHELPERS_STD_HASH(android::details::TMat44);

#undef PURE
#undef CONSTEXPR
+2 −0
Original line number Diff line number Diff line
@@ -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
Loading