[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
This commit is contained in:
parent
50e07d1c92
commit
038e392ebd
@ -257,6 +257,7 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <functional>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <ios>
|
#include <ios>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
@ -1199,27 +1200,27 @@ class PairMatchBase {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
class Eq2Matcher : public PairMatchBase<Eq2Matcher, AnyEq> {
|
class Eq2Matcher : public PairMatchBase<Eq2Matcher, std::equal_to<>> {
|
||||||
public:
|
public:
|
||||||
static const char* Desc() { return "an equal pair"; }
|
static const char* Desc() { return "an equal pair"; }
|
||||||
};
|
};
|
||||||
class Ne2Matcher : public PairMatchBase<Ne2Matcher, AnyNe> {
|
class Ne2Matcher : public PairMatchBase<Ne2Matcher, std::not_equal_to<>> {
|
||||||
public:
|
public:
|
||||||
static const char* Desc() { return "an unequal pair"; }
|
static const char* Desc() { return "an unequal pair"; }
|
||||||
};
|
};
|
||||||
class Lt2Matcher : public PairMatchBase<Lt2Matcher, AnyLt> {
|
class Lt2Matcher : public PairMatchBase<Lt2Matcher, std::less<>> {
|
||||||
public:
|
public:
|
||||||
static const char* Desc() { return "a pair where the first < the second"; }
|
static const char* Desc() { return "a pair where the first < the second"; }
|
||||||
};
|
};
|
||||||
class Gt2Matcher : public PairMatchBase<Gt2Matcher, AnyGt> {
|
class Gt2Matcher : public PairMatchBase<Gt2Matcher, std::greater<>> {
|
||||||
public:
|
public:
|
||||||
static const char* Desc() { return "a pair where the first > the second"; }
|
static const char* Desc() { return "a pair where the first > the second"; }
|
||||||
};
|
};
|
||||||
class Le2Matcher : public PairMatchBase<Le2Matcher, AnyLe> {
|
class Le2Matcher : public PairMatchBase<Le2Matcher, std::less_equal<>> {
|
||||||
public:
|
public:
|
||||||
static const char* Desc() { return "a pair where the first <= the second"; }
|
static const char* Desc() { return "a pair where the first <= the second"; }
|
||||||
};
|
};
|
||||||
class Ge2Matcher : public PairMatchBase<Ge2Matcher, AnyGe> {
|
class Ge2Matcher : public PairMatchBase<Ge2Matcher, std::greater_equal<>> {
|
||||||
public:
|
public:
|
||||||
static const char* Desc() { return "a pair where the first >= the second"; }
|
static const char* Desc() { return "a pair where the first >= the second"; }
|
||||||
};
|
};
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
#define GOOGLETEST_INCLUDE_GTEST_GTEST_MATCHERS_H_
|
#define GOOGLETEST_INCLUDE_GTEST_GTEST_MATCHERS_H_
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -178,43 +179,6 @@ class MatcherInterface : public MatcherDescriberInterface {
|
|||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
struct AnyEq {
|
|
||||||
template <typename A, typename B>
|
|
||||||
bool operator()(const A& a, const B& b) const {
|
|
||||||
return a == b;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct AnyNe {
|
|
||||||
template <typename A, typename B>
|
|
||||||
bool operator()(const A& a, const B& b) const {
|
|
||||||
return a != b;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct AnyLt {
|
|
||||||
template <typename A, typename B>
|
|
||||||
bool operator()(const A& a, const B& b) const {
|
|
||||||
return a < b;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct AnyGt {
|
|
||||||
template <typename A, typename B>
|
|
||||||
bool operator()(const A& a, const B& b) const {
|
|
||||||
return a > b;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct AnyLe {
|
|
||||||
template <typename A, typename B>
|
|
||||||
bool operator()(const A& a, const B& b) const {
|
|
||||||
return a <= b;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct AnyGe {
|
|
||||||
template <typename A, typename B>
|
|
||||||
bool operator()(const A& a, const B& b) const {
|
|
||||||
return a >= b;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// A match result listener that ignores the explanation.
|
// A match result listener that ignores the explanation.
|
||||||
class DummyMatchResultListener : public MatchResultListener {
|
class DummyMatchResultListener : public MatchResultListener {
|
||||||
public:
|
public:
|
||||||
@ -758,50 +722,53 @@ class ComparisonBase {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Rhs>
|
template <typename Rhs>
|
||||||
class EqMatcher : public ComparisonBase<EqMatcher<Rhs>, Rhs, AnyEq> {
|
class EqMatcher : public ComparisonBase<EqMatcher<Rhs>, Rhs, std::equal_to<>> {
|
||||||
public:
|
public:
|
||||||
explicit EqMatcher(const Rhs& rhs)
|
explicit EqMatcher(const Rhs& rhs)
|
||||||
: ComparisonBase<EqMatcher<Rhs>, Rhs, AnyEq>(rhs) {}
|
: ComparisonBase<EqMatcher<Rhs>, Rhs, std::equal_to<>>(rhs) {}
|
||||||
static const char* Desc() { return "is equal to"; }
|
static const char* Desc() { return "is equal to"; }
|
||||||
static const char* NegatedDesc() { return "isn't equal to"; }
|
static const char* NegatedDesc() { return "isn't equal to"; }
|
||||||
};
|
};
|
||||||
template <typename Rhs>
|
template <typename Rhs>
|
||||||
class NeMatcher : public ComparisonBase<NeMatcher<Rhs>, Rhs, AnyNe> {
|
class NeMatcher
|
||||||
|
: public ComparisonBase<NeMatcher<Rhs>, Rhs, std::not_equal_to<>> {
|
||||||
public:
|
public:
|
||||||
explicit NeMatcher(const Rhs& rhs)
|
explicit NeMatcher(const Rhs& rhs)
|
||||||
: ComparisonBase<NeMatcher<Rhs>, Rhs, AnyNe>(rhs) {}
|
: ComparisonBase<NeMatcher<Rhs>, Rhs, std::not_equal_to<>>(rhs) {}
|
||||||
static const char* Desc() { return "isn't equal to"; }
|
static const char* Desc() { return "isn't equal to"; }
|
||||||
static const char* NegatedDesc() { return "is equal to"; }
|
static const char* NegatedDesc() { return "is equal to"; }
|
||||||
};
|
};
|
||||||
template <typename Rhs>
|
template <typename Rhs>
|
||||||
class LtMatcher : public ComparisonBase<LtMatcher<Rhs>, Rhs, AnyLt> {
|
class LtMatcher : public ComparisonBase<LtMatcher<Rhs>, Rhs, std::less<>> {
|
||||||
public:
|
public:
|
||||||
explicit LtMatcher(const Rhs& rhs)
|
explicit LtMatcher(const Rhs& rhs)
|
||||||
: ComparisonBase<LtMatcher<Rhs>, Rhs, AnyLt>(rhs) {}
|
: ComparisonBase<LtMatcher<Rhs>, Rhs, std::less<>>(rhs) {}
|
||||||
static const char* Desc() { return "is <"; }
|
static const char* Desc() { return "is <"; }
|
||||||
static const char* NegatedDesc() { return "isn't <"; }
|
static const char* NegatedDesc() { return "isn't <"; }
|
||||||
};
|
};
|
||||||
template <typename Rhs>
|
template <typename Rhs>
|
||||||
class GtMatcher : public ComparisonBase<GtMatcher<Rhs>, Rhs, AnyGt> {
|
class GtMatcher : public ComparisonBase<GtMatcher<Rhs>, Rhs, std::greater<>> {
|
||||||
public:
|
public:
|
||||||
explicit GtMatcher(const Rhs& rhs)
|
explicit GtMatcher(const Rhs& rhs)
|
||||||
: ComparisonBase<GtMatcher<Rhs>, Rhs, AnyGt>(rhs) {}
|
: ComparisonBase<GtMatcher<Rhs>, Rhs, std::greater<>>(rhs) {}
|
||||||
static const char* Desc() { return "is >"; }
|
static const char* Desc() { return "is >"; }
|
||||||
static const char* NegatedDesc() { return "isn't >"; }
|
static const char* NegatedDesc() { return "isn't >"; }
|
||||||
};
|
};
|
||||||
template <typename Rhs>
|
template <typename Rhs>
|
||||||
class LeMatcher : public ComparisonBase<LeMatcher<Rhs>, Rhs, AnyLe> {
|
class LeMatcher
|
||||||
|
: public ComparisonBase<LeMatcher<Rhs>, Rhs, std::less_equal<>> {
|
||||||
public:
|
public:
|
||||||
explicit LeMatcher(const Rhs& rhs)
|
explicit LeMatcher(const Rhs& rhs)
|
||||||
: ComparisonBase<LeMatcher<Rhs>, Rhs, AnyLe>(rhs) {}
|
: ComparisonBase<LeMatcher<Rhs>, Rhs, std::less_equal<>>(rhs) {}
|
||||||
static const char* Desc() { return "is <="; }
|
static const char* Desc() { return "is <="; }
|
||||||
static const char* NegatedDesc() { return "isn't <="; }
|
static const char* NegatedDesc() { return "isn't <="; }
|
||||||
};
|
};
|
||||||
template <typename Rhs>
|
template <typename Rhs>
|
||||||
class GeMatcher : public ComparisonBase<GeMatcher<Rhs>, Rhs, AnyGe> {
|
class GeMatcher
|
||||||
|
: public ComparisonBase<GeMatcher<Rhs>, Rhs, std::greater_equal<>> {
|
||||||
public:
|
public:
|
||||||
explicit GeMatcher(const Rhs& rhs)
|
explicit GeMatcher(const Rhs& rhs)
|
||||||
: ComparisonBase<GeMatcher<Rhs>, Rhs, AnyGe>(rhs) {}
|
: ComparisonBase<GeMatcher<Rhs>, Rhs, std::greater_equal<>>(rhs) {}
|
||||||
static const char* Desc() { return "is >="; }
|
static const char* Desc() { return "is >="; }
|
||||||
static const char* NegatedDesc() { return "isn't >="; }
|
static const char* NegatedDesc() { return "isn't >="; }
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user