From 1e0ccb1b2150c031a5b601f25cb7fc86dacff9f7 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sun, 13 Oct 2024 10:10:03 +0200 Subject: [PATCH] Use default parameter for comparison instead of overloads in {Unordered}RangeEquals Saves some code duplication. --- .../matchers/catch_matchers_range_equals.hpp | 43 +++++-------------- 1 file changed, 10 insertions(+), 33 deletions(-) diff --git a/src/catch2/matchers/catch_matchers_range_equals.hpp b/src/catch2/matchers/catch_matchers_range_equals.hpp index 41c1c803..49ba19b5 100644 --- a/src/catch2/matchers/catch_matchers_range_equals.hpp +++ b/src/catch2/matchers/catch_matchers_range_equals.hpp @@ -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 - constexpr - std::enable_if_t::value, - RangeEqualsMatcher>> - 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 + template {} )> constexpr RangeEqualsMatcher - 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 - constexpr - std::enable_if_t< - !Detail::is_matcher::value, - UnorderedRangeEqualsMatcher>> - 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 + template {} )> constexpr UnorderedRangeEqualsMatcher - UnorderedRangeEquals( RangeLike&& range, Equality&& predicate ) { + UnorderedRangeEquals( RangeLike&& range, + Equality&& predicate = std::equal_to<>{} ) { return { CATCH_FORWARD( range ), CATCH_FORWARD( predicate ) }; } } // namespace Matchers