Skip to content

Commit 1e0ccb1

Browse files
Stefan Hallerhorenmar
Stefan Haller
authored andcommitted
Use default parameter for comparison instead of overloads in {Unordered}RangeEquals
Saves some code duplication.
1 parent 5ad66ad commit 1e0ccb1

File tree

1 file changed

+10
-33
lines changed

1 file changed

+10
-33
lines changed

src/catch2/matchers/catch_matchers_range_equals.hpp

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -92,58 +92,35 @@ namespace Catch {
9292
}
9393
};
9494

95-
/**
96-
* Creates a matcher that checks if all elements in a range are equal
97-
* to all elements in another range.
98-
*
99-
* Uses `std::equal_to` to do the comparison
100-
*/
101-
template <typename RangeLike>
102-
constexpr
103-
std::enable_if_t<!Detail::is_matcher<RangeLike>::value,
104-
RangeEqualsMatcher<RangeLike, std::equal_to<>>>
105-
RangeEquals( RangeLike&& range ) {
106-
return { CATCH_FORWARD( range ), std::equal_to<>{} };
107-
}
108-
10995
/**
11096
* Creates a matcher that checks if all elements in a range are equal
11197
* to all elements in another range.
11298
*
11399
* Uses the provided predicate `predicate` to do the comparisons
100+
* (defaulting to `std::equal_to`)
114101
*/
115-
template <typename RangeLike, typename Equality>
102+
template <typename RangeLike,
103+
typename Equality = decltype( std::equal_to<>{} )>
116104
constexpr
117105
RangeEqualsMatcher<RangeLike, Equality>
118-
RangeEquals( RangeLike&& range, Equality&& predicate ) {
106+
RangeEquals( RangeLike&& range,
107+
Equality&& predicate = std::equal_to<>{} ) {
119108
return { CATCH_FORWARD( range ), CATCH_FORWARD( predicate ) };
120109
}
121110

122-
/**
123-
* Creates a matcher that checks if all elements in a range are equal
124-
* to all elements in another range, in some permutation
125-
*
126-
* Uses `std::equal_to` to do the comparison
127-
*/
128-
template <typename RangeLike>
129-
constexpr
130-
std::enable_if_t<
131-
!Detail::is_matcher<RangeLike>::value,
132-
UnorderedRangeEqualsMatcher<RangeLike, std::equal_to<>>>
133-
UnorderedRangeEquals( RangeLike&& range ) {
134-
return { CATCH_FORWARD( range ), std::equal_to<>{} };
135-
}
136-
137111
/**
138112
* Creates a matcher that checks if all elements in a range are equal
139113
* to all elements in another range, in some permutation.
140114
*
141115
* Uses the provided predicate `predicate` to do the comparisons
116+
* (defaulting to `std::equal_to`)
142117
*/
143-
template <typename RangeLike, typename Equality>
118+
template <typename RangeLike,
119+
typename Equality = decltype( std::equal_to<>{} )>
144120
constexpr
145121
UnorderedRangeEqualsMatcher<RangeLike, Equality>
146-
UnorderedRangeEquals( RangeLike&& range, Equality&& predicate ) {
122+
UnorderedRangeEquals( RangeLike&& range,
123+
Equality&& predicate = std::equal_to<>{} ) {
147124
return { CATCH_FORWARD( range ), CATCH_FORWARD( predicate ) };
148125
}
149126
} // namespace Matchers

0 commit comments

Comments
 (0)