catch3
Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.
Clonegit clone https://git.progmasoft.com/catch3
Some expression/ evaluation clean-up
- Commit
b5b1b1e430c8c61dbd3162da0255a368ba9ad75f- Author
- Phil Nash ·
- Parents
ec5956f47114
Changes
include/internal/catch_evaluate.hpp | 43 +++++++------------------------ include/internal/catch_expression_lhs.hpp | 2 +- single_include/catch.hpp | 41 +++++++---------------------- 3 files changed, 20 insertions(+), 66 deletions(-) diff --git a/include/internal/catch_evaluate.hpp b/include/internal/catch_evaluate.hpp index 85f12de7..7e9d57d0 100644 --- a/include/internal/catch_evaluate.hpp +++ b/include/internal/catch_evaluate.hpp @@ -69,18 +69,21 @@ namespace Internal { return const_cast<T1&>( lhs ) <= const_cast<T2&>( rhs ); } }; - + template<Operator Op, typename T1, typename T2> bool applyEvaluator( const T1& lhs, const T2& rhs ) { return Evaluator<T1, T2, Op>::evaluate( lhs, rhs ); } - + + // This level of indirection allows us to specialise for integer types + // to avoid signed/ unsigned warnings + // "base" overload template<Operator Op, typename T1, typename T2> bool compare( const T1& lhs, const T2& rhs ) { return Evaluator<T1, T2, Op>::evaluate( lhs, rhs ); } - + // unsigned X to int template<Operator Op> bool compare( unsigned int lhs, int rhs ) { return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) ); @@ -126,44 +129,18 @@ namespace Internal { } // pointer to long (when comparing against NULL) - template<Operator Op, typename T> - bool compare( long lhs, const T* rhs ) { - return Evaluator<const T*, const T*, Op>::evaluate( reinterpret_cast<const T*>( lhs ), rhs ); - } - - template<Operator Op, typename T> - bool compare( long lhs, T* rhs ) { + template<Operator Op, typename T> bool compare( long lhs, T* rhs ) { return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs ); } - - template<Operator Op, typename T> - bool compare( const T* lhs, long rhs ) { - return Evaluator<const T*, const T*, Op>::evaluate( lhs, reinterpret_cast<const T*>( rhs ) ); - } - - template<Operator Op, typename T> - bool compare( T* lhs, long rhs ) { + template<Operator Op, typename T> bool compare( T* lhs, long rhs ) { return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) ); } // pointer to int (when comparing against NULL) - template<Operator Op, typename T> - bool compare( int lhs, const T* rhs ) { - return Evaluator<const T*, const T*, Op>::evaluate( reinterpret_cast<const T*>( lhs ), rhs ); - } - - template<Operator Op, typename T> - bool compare( int lhs, T* rhs ) { + template<Operator Op, typename T> bool compare( int lhs, T* rhs ) { return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs ); } - - template<Operator Op, typename T> - bool compare( const T* lhs, int rhs ) { - return Evaluator<const T*, const T*, Op>::evaluate( lhs, reinterpret_cast<const T*>( rhs ) ); - } - - template<Operator Op, typename T> - bool compare( T* lhs, int rhs ) { + template<Operator Op, typename T> bool compare( T* lhs, int rhs ) { return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) ); } diff --git a/include/internal/catch_expression_lhs.hpp b/include/internal/catch_expression_lhs.hpp index 572c8c37..5804d787 100644 --- a/include/internal/catch_expression_lhs.hpp +++ b/include/internal/catch_expression_lhs.hpp @@ -22,7 +22,7 @@ class ExpressionLhs { void operator = ( const ExpressionLhs& ); public: - ExpressionLhs( T lhs ) : m_lhs( lhs ) {} + ExpressionLhs( const T& lhs ) : m_lhs( lhs ) {} template<typename RhsT> ExpressionResultBuilder& operator == ( const RhsT& rhs ) { diff --git a/single_include/catch.hpp b/single_include/catch.hpp index e92dc0cb..a04b2a4a 100644 --- a/single_include/catch.hpp +++ b/single_include/catch.hpp @@ -1,5 +1,5 @@ /* - * Generated: 2012-11-06 07:51:06.701955 + * Generated: 2012-11-06 19:13:05.717033 * ---------------------------------------------------------- * This file has been merged from multiple headers. Please don't edit it directly * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved. @@ -797,6 +797,9 @@ namespace Internal { return Evaluator<T1, T2, Op>::evaluate( lhs, rhs ); } + // This level of indirection allows us to specialise for integer types + // to avoid signed/ unsigned warnings + // "base" overload template<Operator Op, typename T1, typename T2> bool compare( const T1& lhs, const T2& rhs ) { @@ -848,44 +851,18 @@ namespace Internal { } // pointer to long (when comparing against NULL) - template<Operator Op, typename T> - bool compare( long lhs, const T* rhs ) { - return Evaluator<const T*, const T*, Op>::evaluate( reinterpret_cast<const T*>( lhs ), rhs ); - } - - template<Operator Op, typename T> - bool compare( long lhs, T* rhs ) { + template<Operator Op, typename T> bool compare( long lhs, T* rhs ) { return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs ); } - - template<Operator Op, typename T> - bool compare( const T* lhs, long rhs ) { - return Evaluator<const T*, const T*, Op>::evaluate( lhs, reinterpret_cast<const T*>( rhs ) ); - } - - template<Operator Op, typename T> - bool compare( T* lhs, long rhs ) { + template<Operator Op, typename T> bool compare( T* lhs, long rhs ) { return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) ); } // pointer to int (when comparing against NULL) - template<Operator Op, typename T> - bool compare( int lhs, const T* rhs ) { - return Evaluator<const T*, const T*, Op>::evaluate( reinterpret_cast<const T*>( lhs ), rhs ); - } - - template<Operator Op, typename T> - bool compare( int lhs, T* rhs ) { + template<Operator Op, typename T> bool compare( int lhs, T* rhs ) { return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs ); } - - template<Operator Op, typename T> - bool compare( const T* lhs, int rhs ) { - return Evaluator<const T*, const T*, Op>::evaluate( lhs, reinterpret_cast<const T*>( rhs ) ); - } - - template<Operator Op, typename T> - bool compare( T* lhs, int rhs ) { + template<Operator Op, typename T> bool compare( T* lhs, int rhs ) { return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) ); } @@ -944,7 +921,7 @@ class ExpressionLhs { void operator = ( const ExpressionLhs& ); public: - ExpressionLhs( T lhs ) : m_lhs( lhs ) {} + ExpressionLhs( const T& lhs ) : m_lhs( lhs ) {} template<typename RhsT> ExpressionResultBuilder& operator == ( const RhsT& rhs ) {