Use default parameter for comparison instead of overloads in {Unordered}RangeEquals

Saves some code duplication.
This commit is contained in:
Stefan Haller 2024-10-13 10:10:03 +02:00 committed by Martin Hořeňovský
parent 5ad66ada7b
commit 1e0ccb1b21

View File

@ -92,58 +92,35 @@ namespace Catch {
} }
}; };
/**
* Creates a matcher that checks if all elements in a range are equal
* to all elements in another range.
*
* Uses `std::equal_to` to do the comparison
*/
template <typename RangeLike>
constexpr
std::enable_if_t<!Detail::is_matcher<RangeLike>::value,
RangeEqualsMatcher<RangeLike, std::equal_to<>>>
RangeEquals( RangeLike&& range ) {
return { CATCH_FORWARD( range ), std::equal_to<>{} };
}
/** /**
* Creates a matcher that checks if all elements in a range are equal * Creates a matcher that checks if all elements in a range are equal
* to all elements in another range. * to all elements in another range.
* *
* Uses the provided predicate `predicate` to do the comparisons * Uses the provided predicate `predicate` to do the comparisons
* (defaulting to `std::equal_to`)
*/ */
template <typename RangeLike, typename Equality> template <typename RangeLike,
typename Equality = decltype( std::equal_to<>{} )>
constexpr constexpr
RangeEqualsMatcher<RangeLike, Equality> RangeEqualsMatcher<RangeLike, Equality>
RangeEquals( RangeLike&& range, Equality&& predicate ) { RangeEquals( RangeLike&& range,
Equality&& predicate = std::equal_to<>{} ) {
return { CATCH_FORWARD( range ), CATCH_FORWARD( predicate ) }; return { CATCH_FORWARD( range ), CATCH_FORWARD( predicate ) };
} }
/**
* Creates a matcher that checks if all elements in a range are equal
* to all elements in another range, in some permutation
*
* Uses `std::equal_to` to do the comparison
*/
template <typename RangeLike>
constexpr
std::enable_if_t<
!Detail::is_matcher<RangeLike>::value,
UnorderedRangeEqualsMatcher<RangeLike, std::equal_to<>>>
UnorderedRangeEquals( RangeLike&& range ) {
return { CATCH_FORWARD( range ), std::equal_to<>{} };
}
/** /**
* Creates a matcher that checks if all elements in a range are equal * Creates a matcher that checks if all elements in a range are equal
* to all elements in another range, in some permutation. * to all elements in another range, in some permutation.
* *
* Uses the provided predicate `predicate` to do the comparisons * Uses the provided predicate `predicate` to do the comparisons
* (defaulting to `std::equal_to`)
*/ */
template <typename RangeLike, typename Equality> template <typename RangeLike,
typename Equality = decltype( std::equal_to<>{} )>
constexpr constexpr
UnorderedRangeEqualsMatcher<RangeLike, Equality> UnorderedRangeEqualsMatcher<RangeLike, Equality>
UnorderedRangeEquals( RangeLike&& range, Equality&& predicate ) { UnorderedRangeEquals( RangeLike&& range,
Equality&& predicate = std::equal_to<>{} ) {
return { CATCH_FORWARD( range ), CATCH_FORWARD( predicate ) }; return { CATCH_FORWARD( range ), CATCH_FORWARD( predicate ) };
} }
} // namespace Matchers } // namespace Matchers