summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2018-12-03 19:55:34 (GMT)
committerGennadiy Civil <misterg@google.com>2018-12-04 14:45:03 (GMT)
commit3d71ab4c37de5f13da905a4b60c127176160537d (patch)
tree961eb8a6ba22c823e7d6a13e3feeb49b4cefa5c6
parent3fd66989bb5c70010e8bfe175be35e014fd444c6 (diff)
downloadgoogletest-3d71ab4c37de5f13da905a4b60c127176160537d.zip
googletest-3d71ab4c37de5f13da905a4b60c127176160537d.tar.gz
googletest-3d71ab4c37de5f13da905a4b60c127176160537d.tar.bz2
Googletest export
Deduce SizeType for SizeIs() from the return value of the size() member function PiperOrigin-RevId: 223835674
-rw-r--r--googlemock/include/gmock/gmock-matchers.h4
-rw-r--r--googlemock/test/gmock-matchers_test.cc11
2 files changed, 12 insertions, 3 deletions
diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h
index 801c8df..b859f1a 100644
--- a/googlemock/include/gmock/gmock-matchers.h
+++ b/googlemock/include/gmock/gmock-matchers.h
@@ -1955,9 +1955,7 @@ class SizeIsMatcher {
template <typename Container>
class Impl : public MatcherInterface<Container> {
public:
- typedef internal::StlContainerView<
- GTEST_REMOVE_REFERENCE_AND_CONST_(Container)> ContainerView;
- typedef typename ContainerView::type::size_type SizeType;
+ using SizeType = decltype(std::declval<Container>().size());
explicit Impl(const SizeMatcher& size_matcher)
: size_matcher_(MatcherCast<SizeType>(size_matcher)) {}
diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc
index 5dc09f3..dd4931b 100644
--- a/googlemock/test/gmock-matchers_test.cc
+++ b/googlemock/test/gmock-matchers_test.cc
@@ -4821,6 +4821,17 @@ TEST(SizeIsTest, WorksWithReferences) {
EXPECT_THAT(container, m);
}
+// SizeIs should work for any type that provides a size() member function.
+// For example, a size_type member type should not need to be provided.
+struct MinimalistCustomType {
+ int size() const { return 1; }
+};
+TEST(SizeIsTest, WorksWithMinimalistCustomType) {
+ MinimalistCustomType container;
+ EXPECT_THAT(container, SizeIs(1));
+ EXPECT_THAT(container, Not(SizeIs(0)));
+}
+
TEST(SizeIsTest, CanDescribeSelf) {
Matcher<vector<int> > m = SizeIs(2);
EXPECT_EQ("size is equal to 2", Describe(m));