From 038e392ebd8081c756e180475cc361f711fb438d Mon Sep 17 00:00:00 2001 From: Lawrence Wolf-Sonkin Date: Fri, 10 Mar 2023 14:42:38 -0800 Subject: [gtest] Drop custom-rolled heterogeneous comparator functors in favor of C++ standard ones * Standard heterogeneous comparator functors such as `std::equal_to<>` and `std::less<>` [have been available since C++14](https://en.cppreference.com/w/cpp/utility/functional/less_void) * Now that [C++14 is the minimum supported version of C++ in Googletest](https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md), let's delete these duplications of the standard library PiperOrigin-RevId: 515743068 Change-Id: I1563a2f94039c3a6688429298555545a922f6d7e --- googlemock/include/gmock/gmock-matchers.h | 13 ++++--- googletest/include/gtest/gtest-matchers.h | 65 ++++++++----------------------- 2 files changed, 23 insertions(+), 55 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index fc00c35..6b264d6 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -257,6 +257,7 @@ #include #include +#include #include #include #include @@ -1199,27 +1200,27 @@ class PairMatchBase { }; }; -class Eq2Matcher : public PairMatchBase { +class Eq2Matcher : public PairMatchBase> { public: static const char* Desc() { return "an equal pair"; } }; -class Ne2Matcher : public PairMatchBase { +class Ne2Matcher : public PairMatchBase> { public: static const char* Desc() { return "an unequal pair"; } }; -class Lt2Matcher : public PairMatchBase { +class Lt2Matcher : public PairMatchBase> { public: static const char* Desc() { return "a pair where the first < the second"; } }; -class Gt2Matcher : public PairMatchBase { +class Gt2Matcher : public PairMatchBase> { public: static const char* Desc() { return "a pair where the first > the second"; } }; -class Le2Matcher : public PairMatchBase { +class Le2Matcher : public PairMatchBase> { public: static const char* Desc() { return "a pair where the first <= the second"; } }; -class Ge2Matcher : public PairMatchBase { +class Ge2Matcher : public PairMatchBase> { public: static const char* Desc() { return "a pair where the first >= the second"; } }; diff --git a/googletest/include/gtest/gtest-matchers.h b/googletest/include/gtest/gtest-matchers.h index 4a60b0d..d73d834 100644 --- a/googletest/include/gtest/gtest-matchers.h +++ b/googletest/include/gtest/gtest-matchers.h @@ -40,6 +40,7 @@ #define GOOGLETEST_INCLUDE_GTEST_GTEST_MATCHERS_H_ #include +#include #include #include #include @@ -178,43 +179,6 @@ class MatcherInterface : public MatcherDescriberInterface { namespace internal { -struct AnyEq { - template - bool operator()(const A& a, const B& b) const { - return a == b; - } -}; -struct AnyNe { - template - bool operator()(const A& a, const B& b) const { - return a != b; - } -}; -struct AnyLt { - template - bool operator()(const A& a, const B& b) const { - return a < b; - } -}; -struct AnyGt { - template - bool operator()(const A& a, const B& b) const { - return a > b; - } -}; -struct AnyLe { - template - bool operator()(const A& a, const B& b) const { - return a <= b; - } -}; -struct AnyGe { - template - bool operator()(const A& a, const B& b) const { - return a >= b; - } -}; - // A match result listener that ignores the explanation. class DummyMatchResultListener : public MatchResultListener { public: @@ -758,50 +722,53 @@ class ComparisonBase { }; template -class EqMatcher : public ComparisonBase, Rhs, AnyEq> { +class EqMatcher : public ComparisonBase, Rhs, std::equal_to<>> { public: explicit EqMatcher(const Rhs& rhs) - : ComparisonBase, Rhs, AnyEq>(rhs) {} + : ComparisonBase, Rhs, std::equal_to<>>(rhs) {} static const char* Desc() { return "is equal to"; } static const char* NegatedDesc() { return "isn't equal to"; } }; template -class NeMatcher : public ComparisonBase, Rhs, AnyNe> { +class NeMatcher + : public ComparisonBase, Rhs, std::not_equal_to<>> { public: explicit NeMatcher(const Rhs& rhs) - : ComparisonBase, Rhs, AnyNe>(rhs) {} + : ComparisonBase, Rhs, std::not_equal_to<>>(rhs) {} static const char* Desc() { return "isn't equal to"; } static const char* NegatedDesc() { return "is equal to"; } }; template -class LtMatcher : public ComparisonBase, Rhs, AnyLt> { +class LtMatcher : public ComparisonBase, Rhs, std::less<>> { public: explicit LtMatcher(const Rhs& rhs) - : ComparisonBase, Rhs, AnyLt>(rhs) {} + : ComparisonBase, Rhs, std::less<>>(rhs) {} static const char* Desc() { return "is <"; } static const char* NegatedDesc() { return "isn't <"; } }; template -class GtMatcher : public ComparisonBase, Rhs, AnyGt> { +class GtMatcher : public ComparisonBase, Rhs, std::greater<>> { public: explicit GtMatcher(const Rhs& rhs) - : ComparisonBase, Rhs, AnyGt>(rhs) {} + : ComparisonBase, Rhs, std::greater<>>(rhs) {} static const char* Desc() { return "is >"; } static const char* NegatedDesc() { return "isn't >"; } }; template -class LeMatcher : public ComparisonBase, Rhs, AnyLe> { +class LeMatcher + : public ComparisonBase, Rhs, std::less_equal<>> { public: explicit LeMatcher(const Rhs& rhs) - : ComparisonBase, Rhs, AnyLe>(rhs) {} + : ComparisonBase, Rhs, std::less_equal<>>(rhs) {} static const char* Desc() { return "is <="; } static const char* NegatedDesc() { return "isn't <="; } }; template -class GeMatcher : public ComparisonBase, Rhs, AnyGe> { +class GeMatcher + : public ComparisonBase, Rhs, std::greater_equal<>> { public: explicit GeMatcher(const Rhs& rhs) - : ComparisonBase, Rhs, AnyGe>(rhs) {} + : ComparisonBase, Rhs, std::greater_equal<>>(rhs) {} static const char* Desc() { return "is >="; } static const char* NegatedDesc() { return "isn't >="; } }; -- cgit v0.12