From 6ec14dfd8c409d05fba94e18e3a02df35b874353 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 31 Oct 2025 13:55:24 -0700 Subject: [PATCH] Modernize example of combining matchers. As of C++14 an ordinary function can have an `auto` return type. PiperOrigin-RevId: 826617761 Change-Id: I2ceecc8430643c0ac7843fb216b5a117cfe10ab3 --- docs/gmock_cook_book.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/gmock_cook_book.md b/docs/gmock_cook_book.md index 9e59b4cf..22ad0214 100644 --- a/docs/gmock_cook_book.md +++ b/docs/gmock_cook_book.md @@ -900,15 +900,16 @@ using ::testing::Not; Matchers are function objects, and parametrized matchers can be composed just like any other function. However because their types can be long and rarely -provide meaningful information, it can be easier to express them with C++14 -generic lambdas to avoid specifying types. For example, +provide meaningful information, it can be easier to express them with template +parameters and `auto`. For example, ```cpp using ::testing::Contains; using ::testing::Property; -inline constexpr auto HasFoo = [](const auto& f) { - return Property("foo", &MyClass::foo, Contains(f)); +template +inline constexpr auto HasFoo(const SubMatcher& sub_matcher) { + return Property("foo", &MyClass::foo, Contains(sub_matcher)); }; ... EXPECT_THAT(x, HasFoo("blah"));