Skip to content

Commit

Permalink
Use default parameter for comparison instead of overloads in {Unorder…
Browse files Browse the repository at this point in the history
…ed}RangeEquals

Saves some code duplication.
  • Loading branch information
Stefan Haller committed Oct 13, 2024
1 parent 36e2d9a commit 5328f90
Showing 1 changed file with 10 additions and 33 deletions.
43 changes: 10 additions & 33 deletions src/catch2/matchers/catch_matchers_range_equals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
* to all elements in another range.
*
* 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
RangeEqualsMatcher<RangeLike, Equality>
RangeEquals( RangeLike&& range, Equality&& predicate ) {
RangeEquals( RangeLike&& range,
Equality&& predicate = std::equal_to<>{} ) {
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
* to all elements in another range, in some permutation.
*
* 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
UnorderedRangeEqualsMatcher<RangeLike, Equality>
UnorderedRangeEquals( RangeLike&& range, Equality&& predicate ) {
UnorderedRangeEquals( RangeLike&& range,
Equality&& predicate = std::equal_to<>{} ) {
return { CATCH_FORWARD( range ), CATCH_FORWARD( predicate ) };
}
} // namespace Matchers
Expand Down

0 comments on commit 5328f90

Please sign in to comment.