Remove non-variadic pre C++11 AnyOf
PiperOrigin-RevId: 216411381
This commit is contained in:
parent
7d3b73c85a
commit
78761b58fc
@ -299,94 +299,6 @@ class ArgsMatcher {
|
||||
GTEST_DISALLOW_ASSIGN_(ArgsMatcher);
|
||||
};
|
||||
|
||||
// A set of metafunctions for computing the result type of AnyOf.
|
||||
// AnyOf(m1, ..., mN) returns
|
||||
// AnyOfResultN<decltype(m1), ..., decltype(mN)>::type.
|
||||
|
||||
// Although AnyOf isn't defined for one argument, AnyOfResult1 is defined
|
||||
// to simplify the implementation.
|
||||
template <typename M1>
|
||||
struct AnyOfResult1 {
|
||||
typedef M1 type;
|
||||
};
|
||||
|
||||
template <typename M1, typename M2>
|
||||
struct AnyOfResult2 {
|
||||
typedef EitherOfMatcher<
|
||||
typename AnyOfResult1<M1>::type,
|
||||
typename AnyOfResult1<M2>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
template <typename M1, typename M2, typename M3>
|
||||
struct AnyOfResult3 {
|
||||
typedef EitherOfMatcher<
|
||||
typename AnyOfResult1<M1>::type,
|
||||
typename AnyOfResult2<M2, M3>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4>
|
||||
struct AnyOfResult4 {
|
||||
typedef EitherOfMatcher<
|
||||
typename AnyOfResult2<M1, M2>::type,
|
||||
typename AnyOfResult2<M3, M4>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4, typename M5>
|
||||
struct AnyOfResult5 {
|
||||
typedef EitherOfMatcher<
|
||||
typename AnyOfResult2<M1, M2>::type,
|
||||
typename AnyOfResult3<M3, M4, M5>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4, typename M5,
|
||||
typename M6>
|
||||
struct AnyOfResult6 {
|
||||
typedef EitherOfMatcher<
|
||||
typename AnyOfResult3<M1, M2, M3>::type,
|
||||
typename AnyOfResult3<M4, M5, M6>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4, typename M5,
|
||||
typename M6, typename M7>
|
||||
struct AnyOfResult7 {
|
||||
typedef EitherOfMatcher<
|
||||
typename AnyOfResult3<M1, M2, M3>::type,
|
||||
typename AnyOfResult4<M4, M5, M6, M7>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4, typename M5,
|
||||
typename M6, typename M7, typename M8>
|
||||
struct AnyOfResult8 {
|
||||
typedef EitherOfMatcher<
|
||||
typename AnyOfResult4<M1, M2, M3, M4>::type,
|
||||
typename AnyOfResult4<M5, M6, M7, M8>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4, typename M5,
|
||||
typename M6, typename M7, typename M8, typename M9>
|
||||
struct AnyOfResult9 {
|
||||
typedef EitherOfMatcher<
|
||||
typename AnyOfResult4<M1, M2, M3, M4>::type,
|
||||
typename AnyOfResult5<M5, M6, M7, M8, M9>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4, typename M5,
|
||||
typename M6, typename M7, typename M8, typename M9, typename M10>
|
||||
struct AnyOfResult10 {
|
||||
typedef EitherOfMatcher<
|
||||
typename AnyOfResult5<M1, M2, M3, M4, M5>::type,
|
||||
typename AnyOfResult5<M6, M7, M8, M9, M10>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// Args<N1, N2, ..., Nk>(a_matcher) matches a tuple if the selected
|
||||
@ -469,89 +381,6 @@ Args(const InnerMatcher& matcher) {
|
||||
|
||||
|
||||
|
||||
// AnyOf(m1, m2, ..., mk) matches any value that matches any of the given
|
||||
// sub-matchers. AnyOf is called fully qualified to prevent ADL from firing.
|
||||
|
||||
template <typename M1, typename M2>
|
||||
inline typename internal::AnyOfResult2<M1, M2>::type
|
||||
AnyOf(M1 m1, M2 m2) {
|
||||
return typename internal::AnyOfResult2<M1, M2>::type(
|
||||
m1,
|
||||
m2);
|
||||
}
|
||||
|
||||
template <typename M1, typename M2, typename M3>
|
||||
inline typename internal::AnyOfResult3<M1, M2, M3>::type
|
||||
AnyOf(M1 m1, M2 m2, M3 m3) {
|
||||
return typename internal::AnyOfResult3<M1, M2, M3>::type(
|
||||
m1,
|
||||
::testing::AnyOf(m2, m3));
|
||||
}
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4>
|
||||
inline typename internal::AnyOfResult4<M1, M2, M3, M4>::type
|
||||
AnyOf(M1 m1, M2 m2, M3 m3, M4 m4) {
|
||||
return typename internal::AnyOfResult4<M1, M2, M3, M4>::type(
|
||||
::testing::AnyOf(m1, m2),
|
||||
::testing::AnyOf(m3, m4));
|
||||
}
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4, typename M5>
|
||||
inline typename internal::AnyOfResult5<M1, M2, M3, M4, M5>::type
|
||||
AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5) {
|
||||
return typename internal::AnyOfResult5<M1, M2, M3, M4, M5>::type(
|
||||
::testing::AnyOf(m1, m2),
|
||||
::testing::AnyOf(m3, m4, m5));
|
||||
}
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4, typename M5,
|
||||
typename M6>
|
||||
inline typename internal::AnyOfResult6<M1, M2, M3, M4, M5, M6>::type
|
||||
AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6) {
|
||||
return typename internal::AnyOfResult6<M1, M2, M3, M4, M5, M6>::type(
|
||||
::testing::AnyOf(m1, m2, m3),
|
||||
::testing::AnyOf(m4, m5, m6));
|
||||
}
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4, typename M5,
|
||||
typename M6, typename M7>
|
||||
inline typename internal::AnyOfResult7<M1, M2, M3, M4, M5, M6, M7>::type
|
||||
AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7) {
|
||||
return typename internal::AnyOfResult7<M1, M2, M3, M4, M5, M6, M7>::type(
|
||||
::testing::AnyOf(m1, m2, m3),
|
||||
::testing::AnyOf(m4, m5, m6, m7));
|
||||
}
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4, typename M5,
|
||||
typename M6, typename M7, typename M8>
|
||||
inline typename internal::AnyOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type
|
||||
AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8) {
|
||||
return typename internal::AnyOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type(
|
||||
::testing::AnyOf(m1, m2, m3, m4),
|
||||
::testing::AnyOf(m5, m6, m7, m8));
|
||||
}
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4, typename M5,
|
||||
typename M6, typename M7, typename M8, typename M9>
|
||||
inline typename internal::AnyOfResult9<M1, M2, M3, M4, M5, M6, M7, M8, M9>::type
|
||||
AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9) {
|
||||
return typename internal::AnyOfResult9<M1, M2, M3, M4, M5, M6, M7, M8,
|
||||
M9>::type(
|
||||
::testing::AnyOf(m1, m2, m3, m4),
|
||||
::testing::AnyOf(m5, m6, m7, m8, m9));
|
||||
}
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4, typename M5,
|
||||
typename M6, typename M7, typename M8, typename M9, typename M10>
|
||||
inline typename internal::AnyOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
|
||||
M10>::type
|
||||
AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
return typename internal::AnyOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
|
||||
M10>::type(
|
||||
::testing::AnyOf(m1, m2, m3, m4, m5),
|
||||
::testing::AnyOf(m6, m7, m8, m9, m10));
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
|
||||
|
||||
|
@ -188,36 +188,6 @@ class ArgsMatcher {
|
||||
GTEST_DISALLOW_ASSIGN_(ArgsMatcher);
|
||||
};
|
||||
|
||||
// A set of metafunctions for computing the result type of AnyOf.
|
||||
// AnyOf(m1, ..., mN) returns
|
||||
// AnyOfResultN<decltype(m1), ..., decltype(mN)>::type.
|
||||
|
||||
// Although AnyOf isn't defined for one argument, AnyOfResult1 is defined
|
||||
// to simplify the implementation.
|
||||
template <typename M1>
|
||||
struct AnyOfResult1 {
|
||||
typedef M1 type;
|
||||
};
|
||||
|
||||
$range i 1..n
|
||||
|
||||
$range i 2..n
|
||||
$for i [[
|
||||
$range j 2..i
|
||||
$var m = i/2
|
||||
$range k 1..m
|
||||
$range t m+1..i
|
||||
|
||||
template <typename M1$for j [[, typename M$j]]>
|
||||
struct AnyOfResult$i {
|
||||
typedef EitherOfMatcher<
|
||||
typename AnyOfResult$m<$for k, [[M$k]]>::type,
|
||||
typename AnyOfResult$(i-m)<$for t, [[M$t]]>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
]]
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// Args<N1, N2, ..., Nk>(a_matcher) matches a tuple if the selected
|
||||
@ -234,26 +204,6 @@ Args(const InnerMatcher& matcher) {
|
||||
}
|
||||
|
||||
|
||||
]]
|
||||
|
||||
// AnyOf(m1, m2, ..., mk) matches any value that matches any of the given
|
||||
// sub-matchers. AnyOf is called fully qualified to prevent ADL from firing.
|
||||
|
||||
$range i 2..n
|
||||
$for i [[
|
||||
$range j 1..i
|
||||
$var m = i/2
|
||||
$range k 1..m
|
||||
$range t m+1..i
|
||||
|
||||
template <$for j, [[typename M$j]]>
|
||||
inline typename internal::AnyOfResult$i<$for j, [[M$j]]>::type
|
||||
AnyOf($for j, [[M$j m$j]]) {
|
||||
return typename internal::AnyOfResult$i<$for j, [[M$j]]>::type(
|
||||
$if m == 1 [[m1]] $else [[::testing::AnyOf($for k, [[m$k]])]],
|
||||
$if m+1 == i [[m$i]] $else [[::testing::AnyOf($for t, [[m$t]])]]);
|
||||
}
|
||||
|
||||
]]
|
||||
|
||||
} // namespace testing
|
||||
|
@ -1879,40 +1879,10 @@ class AnyOfMatcherImpl
|
||||
GTEST_DISALLOW_ASSIGN_(AnyOfMatcherImpl);
|
||||
};
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
// AnyOfMatcher is used for the variadic implementation of AnyOf(m_1, m_2, ...).
|
||||
template <typename... Args>
|
||||
using AnyOfMatcher = VariadicMatcher<AnyOfMatcherImpl, Args...>;
|
||||
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
// Used for implementing the AnyOf(m_1, ..., m_n) matcher, which
|
||||
// matches a value that matches at least one of the matchers m_1, ...,
|
||||
// and m_n.
|
||||
template <typename Matcher1, typename Matcher2>
|
||||
class EitherOfMatcher {
|
||||
public:
|
||||
EitherOfMatcher(Matcher1 matcher1, Matcher2 matcher2)
|
||||
: matcher1_(matcher1), matcher2_(matcher2) {}
|
||||
|
||||
// This template type conversion operator allows a
|
||||
// EitherOfMatcher<Matcher1, Matcher2> object to match any type that
|
||||
// both Matcher1 and Matcher2 can match.
|
||||
template <typename T>
|
||||
operator Matcher<T>() const {
|
||||
std::vector<Matcher<T> > values;
|
||||
values.push_back(SafeMatcherCast<T>(matcher1_));
|
||||
values.push_back(SafeMatcherCast<T>(matcher2_));
|
||||
return Matcher<T>(new AnyOfMatcherImpl<T>(internal::move(values)));
|
||||
}
|
||||
|
||||
private:
|
||||
Matcher1 matcher1_;
|
||||
Matcher2 matcher2_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(EitherOfMatcher);
|
||||
};
|
||||
|
||||
// Used for implementing Truly(pred), which turns a predicate into a
|
||||
// matcher.
|
||||
template <typename Predicate>
|
||||
|
@ -2790,28 +2790,22 @@ TEST(ElementsAreTest, HugeMatcherUnordered) {
|
||||
TEST(AnyOfTest, CanDescribeSelf) {
|
||||
Matcher<int> m;
|
||||
m = AnyOf(Le(1), Ge(3));
|
||||
|
||||
EXPECT_EQ("(is <= 1) or (is >= 3)",
|
||||
Describe(m));
|
||||
|
||||
m = AnyOf(Lt(0), Eq(1), Eq(2));
|
||||
EXPECT_EQ("(is < 0) or "
|
||||
"((is equal to 1) or (is equal to 2))",
|
||||
Describe(m));
|
||||
EXPECT_EQ("(is < 0) or (is equal to 1) or (is equal to 2)", Describe(m));
|
||||
|
||||
m = AnyOf(Lt(0), Eq(1), Eq(2), Eq(3));
|
||||
EXPECT_EQ("((is < 0) or "
|
||||
"(is equal to 1)) or "
|
||||
"((is equal to 2) or "
|
||||
"(is equal to 3))",
|
||||
EXPECT_EQ("(is < 0) or (is equal to 1) or (is equal to 2) or (is equal to 3)",
|
||||
Describe(m));
|
||||
|
||||
m = AnyOf(Le(0), Gt(10), 3, 5, 7);
|
||||
EXPECT_EQ("((is <= 0) or "
|
||||
"(is > 10)) or "
|
||||
"((is equal to 3) or "
|
||||
"((is equal to 5) or "
|
||||
"(is equal to 7)))",
|
||||
Describe(m));
|
||||
EXPECT_EQ(
|
||||
"(is <= 0) or (is > 10) or (is equal to 3) or (is equal to 5) or (is "
|
||||
"equal to 7)",
|
||||
Describe(m));
|
||||
}
|
||||
|
||||
// Tests that AnyOf(m1, ..., mn) describes its negation properly.
|
||||
@ -2822,24 +2816,20 @@ TEST(AnyOfTest, CanDescribeNegation) {
|
||||
DescribeNegation(m));
|
||||
|
||||
m = AnyOf(Lt(0), Eq(1), Eq(2));
|
||||
EXPECT_EQ("(isn't < 0) and "
|
||||
"((isn't equal to 1) and (isn't equal to 2))",
|
||||
EXPECT_EQ("(isn't < 0) and (isn't equal to 1) and (isn't equal to 2)",
|
||||
DescribeNegation(m));
|
||||
|
||||
m = AnyOf(Lt(0), Eq(1), Eq(2), Eq(3));
|
||||
EXPECT_EQ("((isn't < 0) and "
|
||||
"(isn't equal to 1)) and "
|
||||
"((isn't equal to 2) and "
|
||||
"(isn't equal to 3))",
|
||||
DescribeNegation(m));
|
||||
EXPECT_EQ(
|
||||
"(isn't < 0) and (isn't equal to 1) and (isn't equal to 2) and (isn't "
|
||||
"equal to 3)",
|
||||
DescribeNegation(m));
|
||||
|
||||
m = AnyOf(Le(0), Gt(10), 3, 5, 7);
|
||||
EXPECT_EQ("((isn't <= 0) and "
|
||||
"(isn't > 10)) and "
|
||||
"((isn't equal to 3) and "
|
||||
"((isn't equal to 5) and "
|
||||
"(isn't equal to 7)))",
|
||||
DescribeNegation(m));
|
||||
EXPECT_EQ(
|
||||
"(isn't <= 0) and (isn't > 10) and (isn't equal to 3) and (isn't equal "
|
||||
"to 5) and (isn't equal to 7)",
|
||||
DescribeNegation(m));
|
||||
}
|
||||
|
||||
// Tests that monomorphic matchers are safely cast by the AnyOf matcher.
|
||||
|
Loading…
Reference in New Issue
Block a user