Browse Source

Math: Use default pure equality comparison for arbitrary types.

pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
6eeac71290
  1. 37
      src/Math/MathTypeTraits.h

37
src/Math/MathTypeTraits.h

@ -42,20 +42,26 @@
namespace Magnum { namespace Math { namespace Magnum { namespace Math {
#ifndef DOXYGEN_GENERATING_OUTPUT
namespace Implementation {
template<class T> struct MathTypeTraitsDefault {
MathTypeTraitsDefault() = delete;
inline constexpr static bool equals(T a, T b) {
return a == b;
}
};
}
#endif
/** /**
@brief Traits class for numeric types @brief Traits class for numeric types
Traits classes are usable for detecting type features at compile time without Traits classes are usable for detecting type features at compile time without
the need for repeated code such as method overloading or template the need for repeated code such as method overloading or template
specialization for given types. 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<class T> struct MathTypeTraits { template<class T> struct MathTypeTraits: Implementation::MathTypeTraitsDefault<T> {
MathTypeTraits() = delete;
/* /*
* The following values are implemented as inline functions, not as * The following values are implemented as inline functions, not as
* static const variables, because the compiler will inline the return * static const variables, because the compiler will inline the return
@ -77,15 +83,15 @@ template<class T> struct MathTypeTraits {
* *
* Returns minimal difference between numbers to be considered * Returns minimal difference between numbers to be considered
* inequal. Returns 1 for integer types and reasonably small value for * 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(); inline constexpr static T epsilon();
/** /**
* @brief Fuzzy compare * @brief Fuzzy compare
* *
* Uses equality for integer types and fuzzy compare for floating-point * Uses fuzzy compare for floating-point types (using epsilon() value),
* types (using @ref epsilon value). * pure equality comparison everywhere else.
*/ */
static bool equals(T a, T b); static bool equals(T a, T b);
#endif #endif
@ -100,17 +106,10 @@ template<class T> struct MathTypeTraits {
*/ */
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
/* Integral scalar types */ /* Integral scalar types */
namespace Implementation { namespace Implementation {
template<class T> struct MathTypeTraitsIntegral { template<class T> struct MathTypeTraitsIntegral: MathTypeTraitsDefault<T> {
MathTypeTraitsIntegral() = delete; inline constexpr static T epsilon() { return T(1); }
inline constexpr static T epsilon() { return 1; }
inline constexpr static bool equals(T a, T b) {
return a == b;
}
}; };
} }

Loading…
Cancel
Save