From 63392e095ea5c172f828c8a3d947b9c62bc7bd08 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Sun, 6 Aug 2017 00:29:37 +0100 Subject: [PATCH] Refactored Evaluator templates to only be specialised on Op, with Lhs/Rhs types templated on method instead --- include/internal/catch_evaluate.hpp | 88 +++++++++++------------ include/internal/catch_expression_lhs.hpp | 2 +- 2 files changed, 43 insertions(+), 47 deletions(-) diff --git a/include/internal/catch_evaluate.hpp b/include/internal/catch_evaluate.hpp index 8c9a69f9..91e01908 100644 --- a/include/internal/catch_evaluate.hpp +++ b/include/internal/catch_evaluate.hpp @@ -36,71 +36,67 @@ namespace Internal { // So the compare overloads can be operator agnostic we convey the operator as a template // enum, which is used to specialise an Evaluator for doing the comparison. - template + template struct Evaluator{}; - template - struct Evaluator { + template<> + struct Evaluator { + template static bool evaluate( T1 const& lhs, T2 const& rhs) { return bool(removeConst(lhs) == removeConst(rhs) ); } - }; - template - struct Evaluator { - static bool evaluate( T1 const& lhs, T2 const& rhs ) { - return bool(removeConst(lhs) != removeConst(rhs) ); - } - }; - template - struct Evaluator { - static bool evaluate( T1 const& lhs, T2 const& rhs ) { - return bool(removeConst(lhs) < removeConst(rhs) ); - } - }; - template - struct Evaluator { - static bool evaluate( T1 const& lhs, T2 const& rhs ) { - return bool(removeConst(lhs) > removeConst(rhs) ); - } - }; - template - struct Evaluator { - static bool evaluate( T1 const& lhs, T2 const& rhs ) { - return bool(removeConst(lhs) >= removeConst(rhs) ); - } - }; - template - struct Evaluator { - static bool evaluate( T1 const& lhs, T2 const& rhs ) { - return bool(removeConst(lhs) <= removeConst(rhs) ); - } - }; - - // Special case for comparing a pointer to an int (deduced for p==0) - template - struct Evaluator { + template static bool evaluate( int lhs, T* rhs) { return reinterpret_cast( lhs ) == rhs; } - }; - template - struct Evaluator { + template static bool evaluate( T* lhs, int rhs) { return lhs == reinterpret_cast( rhs ); } }; - template - struct Evaluator { + template<> + struct Evaluator { + template + static bool evaluate( T1 const& lhs, T2 const& rhs ) { + return bool(removeConst(lhs) != removeConst(rhs) ); + } + template static bool evaluate( int lhs, T* rhs) { return reinterpret_cast( lhs ) != rhs; } - }; - template - struct Evaluator { + template static bool evaluate( T* lhs, int rhs) { return lhs != reinterpret_cast( rhs ); } }; + template<> + struct Evaluator { + template + static bool evaluate( T1 const& lhs, T2 const& rhs ) { + return bool(removeConst(lhs) < removeConst(rhs) ); + } + }; + template<> + struct Evaluator { + template + static bool evaluate( T1 const& lhs, T2 const& rhs ) { + return bool(removeConst(lhs) > removeConst(rhs) ); + } + }; + template<> + struct Evaluator { + template + static bool evaluate( T1 const& lhs, T2 const& rhs ) { + return bool(removeConst(lhs) >= removeConst(rhs) ); + } + }; + template<> + struct Evaluator { + template + static bool evaluate( T1 const& lhs, T2 const& rhs ) { + return bool(removeConst(lhs) <= removeConst(rhs) ); + } + }; } // end of namespace Internal } // end of namespace Catch diff --git a/include/internal/catch_expression_lhs.hpp b/include/internal/catch_expression_lhs.hpp index 35675aee..08625019 100644 --- a/include/internal/catch_expression_lhs.hpp +++ b/include/internal/catch_expression_lhs.hpp @@ -113,7 +113,7 @@ public: void endExpression() const { m_rb - .setResultType( Internal::Evaluator::evaluate( m_lhs, m_rhs ) ) + .setResultType( Internal::Evaluator::evaluate( m_lhs, m_rhs ) ) .endExpression( *this ); }