From 966b549c88032ec43ecd344ab19ca9ca36c30ad9 Mon Sep 17 00:00:00 2001 From: Roman Perepelitsa Date: Tue, 22 Aug 2017 16:06:26 +0200 Subject: Support ref-qualified member functions in Property(). --- googlemock/include/gmock/gmock-matchers.h | 35 ++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'googlemock/include') diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 3a97c438..c446bf7d 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -2232,7 +2232,10 @@ class FieldMatcher { // Implements the Property() matcher for matching a property // (i.e. return value of a getter method) of an object. -template +// +// Property is a const-qualified member function of Class returning +// PropertyType. +template class PropertyMatcher { public: // The property may have a reference type, so 'const PropertyType&' @@ -2241,8 +2244,7 @@ class PropertyMatcher { // PropertyType being a reference or not. typedef GTEST_REFERENCE_TO_CONST_(PropertyType) RefToConstProperty; - PropertyMatcher(PropertyType (Class::*property)() const, - const Matcher& matcher) + PropertyMatcher(Property property, const Matcher& matcher) : property_(property), matcher_(matcher) {} void DescribeTo(::std::ostream* os) const { @@ -2295,7 +2297,7 @@ class PropertyMatcher { return MatchAndExplainImpl(false_type(), *p, listener); } - PropertyType (Class::*property_)() const; + Property property_; const Matcher matcher_; GTEST_DISALLOW_ASSIGN_(PropertyMatcher); @@ -3908,11 +3910,13 @@ inline PolymorphicMatcher< // Property(&Foo::str, StartsWith("hi")) // matches a Foo object x iff x.str() starts with "hi". template -inline PolymorphicMatcher< - internal::PropertyMatcher > Property( - PropertyType (Class::*property)() const, const PropertyMatcher& matcher) { +inline PolymorphicMatcher > +Property(PropertyType (Class::*property)() const, + const PropertyMatcher& matcher) { return MakePolymorphicMatcher( - internal::PropertyMatcher( + internal::PropertyMatcher( property, MatcherCast(matcher))); // The call to MatcherCast() is required for supporting inner @@ -3921,6 +3925,21 @@ inline PolymorphicMatcher< // to compile where bar() returns an int32 and m is a matcher for int64. } +#if GTEST_LANG_CXX11 +// The same as above but for reference-qualified member functions. +template +inline PolymorphicMatcher > +Property(PropertyType (Class::*property)() const &, + const PropertyMatcher& matcher) { + return MakePolymorphicMatcher( + internal::PropertyMatcher( + property, + MatcherCast(matcher))); +} +#endif + // Creates a matcher that matches an object iff the result of applying // a callable to x matches 'matcher'. // For example, -- cgit v1.2.1