40
40
#define GOOGLETEST_INCLUDE_GTEST_GTEST_MATCHERS_H_
41
41
42
42
#include < atomic>
43
+ #include < functional>
43
44
#include < memory>
44
45
#include < ostream>
45
46
#include < string>
@@ -106,13 +107,13 @@ class MatchResultListener {
106
107
MatchResultListener& operator =(const MatchResultListener&) = delete ;
107
108
};
108
109
109
- inline MatchResultListener::~MatchResultListener () {}
110
+ inline MatchResultListener::~MatchResultListener () = default ;
110
111
111
112
// An instance of a subclass of this knows how to describe itself as a
112
113
// matcher.
113
114
class GTEST_API_ MatcherDescriberInterface {
114
115
public:
115
- virtual ~MatcherDescriberInterface () {}
116
+ virtual ~MatcherDescriberInterface () = default ;
116
117
117
118
// Describes this matcher to an ostream. The function should print
118
119
// a verb phrase that describes the property a value matching this
@@ -178,43 +179,6 @@ class MatcherInterface : public MatcherDescriberInterface {
178
179
179
180
namespace internal {
180
181
181
- struct AnyEq {
182
- template <typename A, typename B>
183
- bool operator ()(const A& a, const B& b) const {
184
- return a == b;
185
- }
186
- };
187
- struct AnyNe {
188
- template <typename A, typename B>
189
- bool operator ()(const A& a, const B& b) const {
190
- return a != b;
191
- }
192
- };
193
- struct AnyLt {
194
- template <typename A, typename B>
195
- bool operator ()(const A& a, const B& b) const {
196
- return a < b;
197
- }
198
- };
199
- struct AnyGt {
200
- template <typename A, typename B>
201
- bool operator ()(const A& a, const B& b) const {
202
- return a > b;
203
- }
204
- };
205
- struct AnyLe {
206
- template <typename A, typename B>
207
- bool operator ()(const A& a, const B& b) const {
208
- return a <= b;
209
- }
210
- };
211
- struct AnyGe {
212
- template <typename A, typename B>
213
- bool operator ()(const A& a, const B& b) const {
214
- return a >= b;
215
- }
216
- };
217
-
218
182
// A match result listener that ignores the explanation.
219
183
class DummyMatchResultListener : public MatchResultListener {
220
184
public:
@@ -530,7 +494,7 @@ template <>
530
494
class GTEST_API_ Matcher<const std::string&>
531
495
: public internal::MatcherBase<const std::string&> {
532
496
public:
533
- Matcher () {}
497
+ Matcher () = default ;
534
498
535
499
explicit Matcher (const MatcherInterface<const std::string&>* impl)
536
500
: internal::MatcherBase<const std::string&>(impl) {}
@@ -552,7 +516,7 @@ template <>
552
516
class GTEST_API_ Matcher<std::string>
553
517
: public internal::MatcherBase<std::string> {
554
518
public:
555
- Matcher () {}
519
+ Matcher () = default ;
556
520
557
521
explicit Matcher (const MatcherInterface<const std::string&>* impl)
558
522
: internal::MatcherBase<std::string>(impl) {}
@@ -580,7 +544,7 @@ template <>
580
544
class GTEST_API_ Matcher<const internal::StringView&>
581
545
: public internal::MatcherBase<const internal::StringView&> {
582
546
public:
583
- Matcher () {}
547
+ Matcher () = default ;
584
548
585
549
explicit Matcher (const MatcherInterface<const internal::StringView&>* impl)
586
550
: internal::MatcherBase<const internal::StringView&>(impl) {}
@@ -606,7 +570,7 @@ template <>
606
570
class GTEST_API_ Matcher<internal::StringView>
607
571
: public internal::MatcherBase<internal::StringView> {
608
572
public:
609
- Matcher () {}
573
+ Matcher () = default ;
610
574
611
575
explicit Matcher (const MatcherInterface<const internal::StringView&>* impl)
612
576
: internal::MatcherBase<internal::StringView>(impl) {}
@@ -758,50 +722,53 @@ class ComparisonBase {
758
722
};
759
723
760
724
template <typename Rhs>
761
- class EqMatcher : public ComparisonBase <EqMatcher<Rhs>, Rhs, AnyEq > {
725
+ class EqMatcher : public ComparisonBase <EqMatcher<Rhs>, Rhs, std::equal_to<> > {
762
726
public:
763
727
explicit EqMatcher (const Rhs& rhs)
764
- : ComparisonBase<EqMatcher<Rhs>, Rhs, AnyEq >(rhs) {}
728
+ : ComparisonBase<EqMatcher<Rhs>, Rhs, std::equal_to<> >(rhs) {}
765
729
static const char * Desc () { return " is equal to" ; }
766
730
static const char * NegatedDesc () { return " isn't equal to" ; }
767
731
};
768
732
template <typename Rhs>
769
- class NeMatcher : public ComparisonBase <NeMatcher<Rhs>, Rhs, AnyNe> {
733
+ class NeMatcher
734
+ : public ComparisonBase<NeMatcher<Rhs>, Rhs, std::not_equal_to<>> {
770
735
public:
771
736
explicit NeMatcher (const Rhs& rhs)
772
- : ComparisonBase<NeMatcher<Rhs>, Rhs, AnyNe >(rhs) {}
737
+ : ComparisonBase<NeMatcher<Rhs>, Rhs, std::not_equal_to<> >(rhs) {}
773
738
static const char * Desc () { return " isn't equal to" ; }
774
739
static const char * NegatedDesc () { return " is equal to" ; }
775
740
};
776
741
template <typename Rhs>
777
- class LtMatcher : public ComparisonBase <LtMatcher<Rhs>, Rhs, AnyLt > {
742
+ class LtMatcher : public ComparisonBase <LtMatcher<Rhs>, Rhs, std::less<> > {
778
743
public:
779
744
explicit LtMatcher (const Rhs& rhs)
780
- : ComparisonBase<LtMatcher<Rhs>, Rhs, AnyLt >(rhs) {}
745
+ : ComparisonBase<LtMatcher<Rhs>, Rhs, std::less<> >(rhs) {}
781
746
static const char * Desc () { return " is <" ; }
782
747
static const char * NegatedDesc () { return " isn't <" ; }
783
748
};
784
749
template <typename Rhs>
785
- class GtMatcher : public ComparisonBase <GtMatcher<Rhs>, Rhs, AnyGt > {
750
+ class GtMatcher : public ComparisonBase <GtMatcher<Rhs>, Rhs, std::greater<> > {
786
751
public:
787
752
explicit GtMatcher (const Rhs& rhs)
788
- : ComparisonBase<GtMatcher<Rhs>, Rhs, AnyGt >(rhs) {}
753
+ : ComparisonBase<GtMatcher<Rhs>, Rhs, std::greater<> >(rhs) {}
789
754
static const char * Desc () { return " is >" ; }
790
755
static const char * NegatedDesc () { return " isn't >" ; }
791
756
};
792
757
template <typename Rhs>
793
- class LeMatcher : public ComparisonBase <LeMatcher<Rhs>, Rhs, AnyLe> {
758
+ class LeMatcher
759
+ : public ComparisonBase<LeMatcher<Rhs>, Rhs, std::less_equal<>> {
794
760
public:
795
761
explicit LeMatcher (const Rhs& rhs)
796
- : ComparisonBase<LeMatcher<Rhs>, Rhs, AnyLe >(rhs) {}
762
+ : ComparisonBase<LeMatcher<Rhs>, Rhs, std::less_equal<> >(rhs) {}
797
763
static const char * Desc () { return " is <=" ; }
798
764
static const char * NegatedDesc () { return " isn't <=" ; }
799
765
};
800
766
template <typename Rhs>
801
- class GeMatcher : public ComparisonBase <GeMatcher<Rhs>, Rhs, AnyGe> {
767
+ class GeMatcher
768
+ : public ComparisonBase<GeMatcher<Rhs>, Rhs, std::greater_equal<>> {
802
769
public:
803
770
explicit GeMatcher (const Rhs& rhs)
804
- : ComparisonBase<GeMatcher<Rhs>, Rhs, AnyGe >(rhs) {}
771
+ : ComparisonBase<GeMatcher<Rhs>, Rhs, std::greater_equal<> >(rhs) {}
805
772
static const char * Desc () { return " is >=" ; }
806
773
static const char * NegatedDesc () { return " isn't >=" ; }
807
774
};
0 commit comments