mirror of
https://github.com/google/googletest.git
synced 2025-11-30 08:07:27 -05:00
Modernize example of combining matchers.
As of C++14 an ordinary function can have an `auto` return type. PiperOrigin-RevId: 826617761 Change-Id: I2ceecc8430643c0ac7843fb216b5a117cfe10ab3
This commit is contained in:
committed by
Copybara-Service
parent
17d335d7c7
commit
6ec14dfd8c
@@ -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 <typename SubMatcher>
|
||||
inline constexpr auto HasFoo(const SubMatcher& sub_matcher) {
|
||||
return Property("foo", &MyClass::foo, Contains(sub_matcher));
|
||||
};
|
||||
...
|
||||
EXPECT_THAT(x, HasFoo("blah"));
|
||||
|
||||
Reference in New Issue
Block a user