diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 801c8dfb..b859f1aa 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -1955,9 +1955,7 @@ class SizeIsMatcher { template class Impl : public MatcherInterface { public: - typedef internal::StlContainerView< - GTEST_REMOVE_REFERENCE_AND_CONST_(Container)> ContainerView; - typedef typename ContainerView::type::size_type SizeType; + using SizeType = decltype(std::declval().size()); explicit Impl(const SizeMatcher& size_matcher) : size_matcher_(MatcherCast(size_matcher)) {} diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 5dc09f35..dd4931be 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 > m = SizeIs(2); EXPECT_EQ("size is equal to 2", Describe(m));