From 6eeac71290303e2ae00d07e991c3105b04333605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 16 Feb 2013 19:28:17 +0100 Subject: [PATCH] Math: Use default pure equality comparison for arbitrary types. --- src/Math/MathTypeTraits.h | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/Math/MathTypeTraits.h b/src/Math/MathTypeTraits.h index 29ca45e00..d60a1eb80 100644 --- a/src/Math/MathTypeTraits.h +++ b/src/Math/MathTypeTraits.h @@ -42,20 +42,26 @@ namespace Magnum { namespace Math { +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { + template struct MathTypeTraitsDefault { + MathTypeTraitsDefault() = delete; + + inline constexpr static bool equals(T a, T b) { + return a == b; + } + }; +} +#endif + /** @brief Traits class for numeric types Traits classes are usable for detecting type features at compile time without the need for repeated code such as method overloading or template specialization for given types. - -This class and class methods are specialized only for types where it makes -sense, it has empty implementation for unknown types or types which don't -support given feature, thus forcing the compilation stop with an error. */ -template struct MathTypeTraits { - MathTypeTraits() = delete; - +template struct MathTypeTraits: Implementation::MathTypeTraitsDefault { /* * The following values are implemented as inline functions, not as * static const variables, because the compiler will inline the return @@ -77,15 +83,15 @@ template struct MathTypeTraits { * * Returns minimal difference between numbers to be considered * inequal. Returns 1 for integer types and reasonably small value for - * floating-point types. + * floating-point types. Not implemented for arbitrary types. */ inline constexpr static T epsilon(); /** * @brief Fuzzy compare * - * Uses equality for integer types and fuzzy compare for floating-point - * types (using @ref epsilon value). + * Uses fuzzy compare for floating-point types (using epsilon() value), + * pure equality comparison everywhere else. */ static bool equals(T a, T b); #endif @@ -100,17 +106,10 @@ template struct MathTypeTraits { */ #ifndef DOXYGEN_GENERATING_OUTPUT - /* Integral scalar types */ namespace Implementation { - template struct MathTypeTraitsIntegral { - MathTypeTraitsIntegral() = delete; - - inline constexpr static T epsilon() { return 1; } - - inline constexpr static bool equals(T a, T b) { - return a == b; - } + template struct MathTypeTraitsIntegral: MathTypeTraitsDefault { + inline constexpr static T epsilon() { return T(1); } }; }