diff --git a/include/internal/catch_evaluate.hpp b/include/internal/catch_evaluate.hpp index b2f47cdd..6b2b47aa 100644 --- a/include/internal/catch_evaluate.hpp +++ b/include/internal/catch_evaluate.hpp @@ -94,120 +94,139 @@ namespace Internal { // This level of indirection allows us to specialise for integer types // to avoid signed/ unsigned warnings + // prevent from overloading ambiguity: SunStudio 11 can't handle function overloads, but can handle class overloads... + template + struct EvaluatorImpl + { + bool operator()(T1 const& lhs, T2 const& rhs) + { + return Evaluator::evaluate( lhs, rhs ); + } + }; + // "base" overload template bool compare( T1 const& lhs, T2 const& rhs ) { - return Evaluator::evaluate( lhs, rhs ); + return EvaluatorImpl() ( lhs, rhs ); } +#undef CATCH_INTERNAL_COMPARE +#undef CATCH_INTERNAL_COMPARE_T +#define CATCH_INTERNAL_COMPARE( LHS, RHS ) template struct EvaluatorImpl { bool operator()(LHS lhs, RHS rhs) +#define CATCH_INTERNAL_COMPARE_T( LHS, RHS ) template struct EvaluatorImpl { bool operator()(LHS lhs, RHS rhs) + // unsigned X to int - template bool compare( unsigned int lhs, int rhs ) { + CATCH_INTERNAL_COMPARE( unsigned int , int ) { return applyEvaluator( lhs, static_cast( rhs ) ); - } - template bool compare( unsigned long lhs, int rhs ) { + }}; + + CATCH_INTERNAL_COMPARE( unsigned long , int ) { return applyEvaluator( lhs, static_cast( rhs ) ); - } - template bool compare( unsigned char lhs, int rhs ) { + }}; + CATCH_INTERNAL_COMPARE( unsigned char , int ) { return applyEvaluator( lhs, static_cast( rhs ) ); - } + }}; // unsigned X to long - template bool compare( unsigned int lhs, long rhs ) { + CATCH_INTERNAL_COMPARE( unsigned int , long ) { return applyEvaluator( lhs, static_cast( rhs ) ); - } - template bool compare( unsigned long lhs, long rhs ) { + }}; + CATCH_INTERNAL_COMPARE( unsigned long , long ) { return applyEvaluator( lhs, static_cast( rhs ) ); - } - template bool compare( unsigned char lhs, long rhs ) { + }}; + CATCH_INTERNAL_COMPARE( unsigned char , long ) { return applyEvaluator( lhs, static_cast( rhs ) ); - } + }}; // int to unsigned X - template bool compare( int lhs, unsigned int rhs ) { + CATCH_INTERNAL_COMPARE( int , unsigned int ) { return applyEvaluator( static_cast( lhs ), rhs ); - } - template bool compare( int lhs, unsigned long rhs ) { + }}; + CATCH_INTERNAL_COMPARE( int , unsigned long ) { return applyEvaluator( static_cast( lhs ), rhs ); - } - template bool compare( int lhs, unsigned char rhs ) { + }}; + CATCH_INTERNAL_COMPARE( int , unsigned char ) { return applyEvaluator( static_cast( lhs ), rhs ); - } + }}; // long to unsigned X - template bool compare( long lhs, unsigned int rhs ) { + CATCH_INTERNAL_COMPARE( long , unsigned int ) { return applyEvaluator( static_cast( lhs ), rhs ); - } - template bool compare( long lhs, unsigned long rhs ) { + }}; + CATCH_INTERNAL_COMPARE( long , unsigned long ) { return applyEvaluator( static_cast( lhs ), rhs ); - } - template bool compare( long lhs, unsigned char rhs ) { + }}; + CATCH_INTERNAL_COMPARE( long , unsigned char ) { return applyEvaluator( static_cast( lhs ), rhs ); - } + }}; // pointer to long (when comparing against NULL) - template bool compare( long lhs, T* rhs ) { + CATCH_INTERNAL_COMPARE_T( long , T* ) { return Evaluator::evaluate( reinterpret_cast( lhs ), rhs ); - } + }}; template bool compare( T* lhs, long rhs ) { return Evaluator::evaluate( lhs, reinterpret_cast( rhs ) ); } // pointer to int (when comparing against NULL) - template bool compare( int lhs, T* rhs ) { + CATCH_INTERNAL_COMPARE_T( int , T* ) { return Evaluator::evaluate( reinterpret_cast( lhs ), rhs ); - } - template bool compare( T* lhs, int rhs ) { + }}; + CATCH_INTERNAL_COMPARE_T( T* , int ) { return Evaluator::evaluate( lhs, reinterpret_cast( rhs ) ); - } + }}; #ifdef CATCH_CONFIG_CPP11_LONG_LONG // long long to unsigned X - template bool compare( long long lhs, unsigned int rhs ) { + CATCH_INTERNAL_COMPARE( long long , unsigned int ) { return applyEvaluator( static_cast( lhs ), rhs ); - } - template bool compare( long long lhs, unsigned long rhs ) { + }}; + CATCH_INTERNAL_COMPARE( long long , unsigned long ) { return applyEvaluator( static_cast( lhs ), rhs ); - } - template bool compare( long long lhs, unsigned long long rhs ) { + }}; + CATCH_INTERNAL_COMPARE( long long , unsigned long long ) { return applyEvaluator( static_cast( lhs ), rhs ); - } - template bool compare( long long lhs, unsigned char rhs ) { + }}; + CATCH_INTERNAL_COMPARE( long long , unsigned char ) { return applyEvaluator( static_cast( lhs ), rhs ); - } + }}; // unsigned long long to X - template bool compare( unsigned long long lhs, int rhs ) { + CATCH_INTERNAL_COMPARE( unsigned long long , int ) { return applyEvaluator( static_cast( lhs ), rhs ); - } - template bool compare( unsigned long long lhs, long rhs ) { + }}; + CATCH_INTERNAL_COMPARE( unsigned long long , long ) { return applyEvaluator( static_cast( lhs ), rhs ); - } - template bool compare( unsigned long long lhs, long long rhs ) { + }}; + CATCH_INTERNAL_COMPARE( unsigned long long , long long ) { return applyEvaluator( static_cast( lhs ), rhs ); - } - template bool compare( unsigned long long lhs, char rhs ) { + }}; + CATCH_INTERNAL_COMPARE( unsigned long long , char ) { return applyEvaluator( static_cast( lhs ), rhs ); - } + }}; // pointer to long long (when comparing against NULL) - template bool compare( long long lhs, T* rhs ) { + CATCH_INTERNAL_COMPARE_T( long long lhs, T* ) { return Evaluator::evaluate( reinterpret_cast( lhs ), rhs ); - } - template bool compare( T* lhs, long long rhs ) { + }}; + CATCH_INTERNAL_COMPARE_T( T* , long long ) { return Evaluator::evaluate( lhs, reinterpret_cast( rhs ) ); - } + }}; #endif // CATCH_CONFIG_CPP11_LONG_LONG #ifdef CATCH_CONFIG_CPP11_NULLPTR // pointer to nullptr_t (when comparing against nullptr) - template bool compare( std::nullptr_t, T* rhs ) { + CATCH_INTERNAL_COMPARE_T( std::nullptr_t, T* ) { return Evaluator::evaluate( nullptr, rhs ); - } - template bool compare( T* lhs, std::nullptr_t ) { + }}; + CATCH_INTERNAL_COMPARE_T( T* , std::nullptr_t ) { return Evaluator::evaluate( lhs, nullptr ); - } + }}; #endif // CATCH_CONFIG_CPP11_NULLPTR +#undef CATCH_INTERNAL_COMPARE +#undef CATCH_INTERNAL_COMPARE_T + } // end of namespace Internal } // end of namespace Catch