diff --git a/internal/catch_unsigned.hpp b/internal/catch_unsigned.hpp index 38989bef..01e31a1a 100644 --- a/internal/catch_unsigned.hpp +++ b/internal/catch_unsigned.hpp @@ -17,89 +17,129 @@ namespace Catch { - template - struct SignTraits{}; - - template<> - struct SignTraits + enum Operator { - typedef int SignedType; - typedef unsigned int UnsignedType; - }; - template<> - struct SignTraits : SignTraits{}; - - template<> - struct SignTraits - { - typedef long SignedType; - typedef unsigned long UnsignedType; - }; - template<> - struct SignTraits : SignTraits{}; - - template<> - struct SignTraits - { - typedef char SignedType; - typedef unsigned char UnsignedType; - }; - template<> - struct SignTraits : SignTraits{}; - - template - struct IsType - { - enum{ result = false }; + IsEqualTo, + IsNotEqualTo, + IsLessThan, + IsGreaterThan, + IsLessThanOrEqualTo, + IsGreaterThanOrEqualTo }; - template - struct IsType - { - enum{ result = true }; - }; - - template - struct MatchedSigns - { - static const T1& castLhs( const T1& lhs ) - { - return lhs; - } - static const T2& castRhs( const T2& rhs ) - { - return rhs; - } - }; + template + class Evaluator{}; template - struct MatchedSigns + struct Evaluator { - typedef typename SignTraits::SignedType Type1; - typedef typename SignTraits::SignedType Type2; - - static Type1 castLhs( T1 lhs ) + static bool evaluate( const T1& lhs, const T2& rhs ) { - return static_cast( lhs ); + return lhs == rhs; } - static Type2 castRhs( T2 rhs ) + }; + template + struct Evaluator + { + static bool evaluate( const T1& lhs, const T2& rhs ) { - return static_cast( rhs ); + return lhs != rhs; + } + }; + template + struct Evaluator + { + static bool evaluate( const T1& lhs, const T2& rhs ) + { + return lhs < rhs; + } + }; + template + struct Evaluator + { + static bool evaluate( const T1& lhs, const T2& rhs ) + { + return lhs > rhs; + } + }; + template + struct Evaluator + { + static bool evaluate( const T1& lhs, const T2& rhs ) + { + return lhs >= rhs; + } + }; + template + struct Evaluator + { + static bool evaluate( const T1& lhs, const T2& rhs ) + { + return lhs <= rhs; } }; - template - struct MatchSign - : MatchedSigns< T1, T2, - ( !IsType::result && - !IsType::result && - !IsType::result && - !IsType::result ) || - !std::numeric_limits::is_integer || - !std::numeric_limits::is_integer || - std::numeric_limits::is_signed == std::numeric_limits::is_signed > + template + bool compare( const T1& lhs, const T2& rhs ) { - }; + return Evaluator::evaluate( lhs, rhs ); + } + + // unsigned X to int + template bool compare( unsigned int lhs, int rhs ) + { + return Evaluator::evaluate( lhs, static_cast( rhs ) ); + } + template bool compare( unsigned long lhs, int rhs ) + { + return Evaluator::evaluate( lhs, static_cast( rhs ) ); + } + template bool compare( unsigned char lhs, int rhs ) + { + return Evaluator::evaluate( lhs, static_cast( rhs ) ); + } + + // unsigned X to long + template bool compare( unsigned int lhs, long rhs ) + { + return Evaluator::evaluate( lhs, static_cast( rhs ) ); + } + template bool compare( unsigned long lhs, long rhs ) + { + return Evaluator::evaluate( lhs, static_cast( rhs ) ); + } + template bool compare( unsigned char lhs, long rhs ) + { + return Evaluator::evaluate( lhs, static_cast( rhs ) ); + } + + // int to unsigned X + template bool compare( int lhs, unsigned int rhs ) + { + return Evaluator::evaluate( static_cast( lhs ), rhs ); + } + template bool compare( int lhs, unsigned long rhs ) + { + return Evaluator::evaluate( static_cast( lhs ), rhs ); + } + template bool compare( int lhs, unsigned char rhs ) + { + return Evaluator::evaluate( static_cast( lhs ), rhs ); + } + + // long to unsigned X + template bool compare( long lhs, unsigned int rhs ) + { + return Evaluator::evaluate( static_cast( lhs ), rhs ); + } + template bool compare( long lhs, unsigned long rhs ) + { + return Evaluator::evaluate( static_cast( lhs ), rhs ); + } + template bool compare( long lhs, unsigned char rhs ) + { + return Evaluator::evaluate( static_cast( lhs ), rhs ); + } } #endif // TWOBLUECUBES_CATCH_UNSIGNED_HPP_INCLUDED