diff options
| author | Stefan Haller | 2024-10-13 10:10:03 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2024-10-14 21:02:03 +0200 |
| commit | 1e0ccb1b2150c031a5b601f25cb7fc86dacff9f7 (patch) | |
| tree | 967040e1d772199683471ea4964576524ea12b41 /src/catch2 | |
| parent | 5ad66ada7b5c1815382b69c6db04685bd93878aa (diff) | |
| download | catch3-1e0ccb1b2150c031a5b601f25cb7fc86dacff9f7.tar.gz | |
Use default parameter for comparison instead of overloads in {Unordered}RangeEquals
Saves some code duplication.
Diffstat (limited to 'src/catch2')
| -rw-r--r-- | src/catch2/matchers/catch_matchers_range_equals.hpp | 43 |
1 files 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 @@ -96,54 +96,31 @@ 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 |