Skip to content

Commit 6ec14df

Browse files
Abseil Teamcopybara-github
authored andcommitted
Modernize example of combining matchers.
As of C++14 an ordinary function can have an `auto` return type. PiperOrigin-RevId: 826617761 Change-Id: I2ceecc8430643c0ac7843fb216b5a117cfe10ab3
1 parent 17d335d commit 6ec14df

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

docs/gmock_cook_book.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -900,15 +900,16 @@ using ::testing::Not;
900900

901901
Matchers are function objects, and parametrized matchers can be composed just
902902
like any other function. However because their types can be long and rarely
903-
provide meaningful information, it can be easier to express them with C++14
904-
generic lambdas to avoid specifying types. For example,
903+
provide meaningful information, it can be easier to express them with template
904+
parameters and `auto`. For example,
905905

906906
```cpp
907907
using ::testing::Contains;
908908
using ::testing::Property;
909909

910-
inline constexpr auto HasFoo = [](const auto& f) {
911-
return Property("foo", &MyClass::foo, Contains(f));
910+
template <typename SubMatcher>
911+
inline constexpr auto HasFoo(const SubMatcher& sub_matcher) {
912+
return Property("foo", &MyClass::foo, Contains(sub_matcher));
912913
};
913914
...
914915
EXPECT_THAT(x, HasFoo("blah"));

0 commit comments

Comments
 (0)