mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
Refactored Evaluator templates to only be specialised on Op, with Lhs/Rhs types templated on method instead
This commit is contained in:
parent
0a2ce87d32
commit
63392e095e
@ -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<typename T1, typename T2, Operator Op>
|
||||
template<Operator Op>
|
||||
struct Evaluator{};
|
||||
|
||||
template<>
|
||||
struct Evaluator<IsEqualTo> {
|
||||
template<typename T1, typename T2>
|
||||
struct Evaluator<T1, T2, IsEqualTo> {
|
||||
static bool evaluate( T1 const& lhs, T2 const& rhs) {
|
||||
return bool(removeConst(lhs) == removeConst(rhs) );
|
||||
}
|
||||
};
|
||||
template<typename T1, typename T2>
|
||||
struct Evaluator<T1, T2, IsNotEqualTo> {
|
||||
static bool evaluate( T1 const& lhs, T2 const& rhs ) {
|
||||
return bool(removeConst(lhs) != removeConst(rhs) );
|
||||
}
|
||||
};
|
||||
template<typename T1, typename T2>
|
||||
struct Evaluator<T1, T2, IsLessThan> {
|
||||
static bool evaluate( T1 const& lhs, T2 const& rhs ) {
|
||||
return bool(removeConst(lhs) < removeConst(rhs) );
|
||||
}
|
||||
};
|
||||
template<typename T1, typename T2>
|
||||
struct Evaluator<T1, T2, IsGreaterThan> {
|
||||
static bool evaluate( T1 const& lhs, T2 const& rhs ) {
|
||||
return bool(removeConst(lhs) > removeConst(rhs) );
|
||||
}
|
||||
};
|
||||
template<typename T1, typename T2>
|
||||
struct Evaluator<T1, T2, IsGreaterThanOrEqualTo> {
|
||||
static bool evaluate( T1 const& lhs, T2 const& rhs ) {
|
||||
return bool(removeConst(lhs) >= removeConst(rhs) );
|
||||
}
|
||||
};
|
||||
template<typename T1, typename T2>
|
||||
struct Evaluator<T1, T2, IsLessThanOrEqualTo> {
|
||||
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<typename T>
|
||||
struct Evaluator<int const&, T* const&, IsEqualTo> {
|
||||
static bool evaluate( int lhs, T* rhs) {
|
||||
return reinterpret_cast<void const*>( lhs ) == rhs;
|
||||
}
|
||||
};
|
||||
template<typename T>
|
||||
struct Evaluator<T* const&, int const&, IsEqualTo> {
|
||||
static bool evaluate( T* lhs, int rhs) {
|
||||
return lhs == reinterpret_cast<void const*>( rhs );
|
||||
}
|
||||
};
|
||||
template<>
|
||||
struct Evaluator<IsNotEqualTo> {
|
||||
template<typename T1, typename T2>
|
||||
static bool evaluate( T1 const& lhs, T2 const& rhs ) {
|
||||
return bool(removeConst(lhs) != removeConst(rhs) );
|
||||
}
|
||||
template<typename T>
|
||||
struct Evaluator<int const&, T* const&, IsNotEqualTo> {
|
||||
static bool evaluate( int lhs, T* rhs) {
|
||||
return reinterpret_cast<void const*>( lhs ) != rhs;
|
||||
}
|
||||
};
|
||||
template<typename T>
|
||||
struct Evaluator<T* const&, int const&, IsNotEqualTo> {
|
||||
static bool evaluate( T* lhs, int rhs) {
|
||||
return lhs != reinterpret_cast<void const*>( rhs );
|
||||
}
|
||||
};
|
||||
template<>
|
||||
struct Evaluator<IsLessThan> {
|
||||
template<typename T1, typename T2>
|
||||
static bool evaluate( T1 const& lhs, T2 const& rhs ) {
|
||||
return bool(removeConst(lhs) < removeConst(rhs) );
|
||||
}
|
||||
};
|
||||
template<>
|
||||
struct Evaluator<IsGreaterThan> {
|
||||
template<typename T1, typename T2>
|
||||
static bool evaluate( T1 const& lhs, T2 const& rhs ) {
|
||||
return bool(removeConst(lhs) > removeConst(rhs) );
|
||||
}
|
||||
};
|
||||
template<>
|
||||
struct Evaluator<IsGreaterThanOrEqualTo> {
|
||||
template<typename T1, typename T2>
|
||||
static bool evaluate( T1 const& lhs, T2 const& rhs ) {
|
||||
return bool(removeConst(lhs) >= removeConst(rhs) );
|
||||
}
|
||||
};
|
||||
template<>
|
||||
struct Evaluator<IsLessThanOrEqualTo> {
|
||||
template<typename T1, typename T2>
|
||||
static bool evaluate( T1 const& lhs, T2 const& rhs ) {
|
||||
return bool(removeConst(lhs) <= removeConst(rhs) );
|
||||
}
|
||||
};
|
||||
|
||||
} // end of namespace Internal
|
||||
} // end of namespace Catch
|
||||
|
@ -113,7 +113,7 @@ public:
|
||||
|
||||
void endExpression() const {
|
||||
m_rb
|
||||
.setResultType( Internal::Evaluator<LhsT, RhsT, Op>::evaluate( m_lhs, m_rhs ) )
|
||||
.setResultType( Internal::Evaluator<Op>::evaluate( m_lhs, m_rhs ) )
|
||||
.endExpression( *this );
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user