From b75ecf1bed2fcd416b66c86cb6fe79122abf132e Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Wed, 7 Feb 2024 15:05:25 -0800 Subject: [PATCH] Switch rank structs to be consistent with written guidance in go/ranked-overloads PiperOrigin-RevId: 605110251 Change-Id: I304f3863333cb9ef0b85c5bab5277e757ef9950a --- googlemock/include/gmock/gmock-matchers.h | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 8052c74a..c4149f2e 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -2920,26 +2920,27 @@ class EachMatcher { const M inner_matcher_; }; -struct Rank1 {}; -struct Rank0 : Rank1 {}; +// Use go/ranked-overloads for dispatching. +struct Rank0 {}; +struct Rank1 : Rank0 {}; namespace pair_getters { using std::get; template -auto First(T& x, Rank1) -> decltype(get<0>(x)) { // NOLINT +auto First(T& x, Rank0) -> decltype(get<0>(x)) { // NOLINT return get<0>(x); } template -auto First(T& x, Rank0) -> decltype((x.first)) { // NOLINT +auto First(T& x, Rank1) -> decltype((x.first)) { // NOLINT return x.first; } template -auto Second(T& x, Rank1) -> decltype(get<1>(x)) { // NOLINT +auto Second(T& x, Rank0) -> decltype(get<1>(x)) { // NOLINT return get<1>(x); } template -auto Second(T& x, Rank0) -> decltype((x.second)) { // NOLINT +auto Second(T& x, Rank1) -> decltype((x.second)) { // NOLINT return x.second; } } // namespace pair_getters @@ -2965,7 +2966,7 @@ class KeyMatcherImpl : public MatcherInterface { MatchResultListener* listener) const override { StringMatchResultListener inner_listener; const bool match = inner_matcher_.MatchAndExplain( - pair_getters::First(key_value, Rank0()), &inner_listener); + pair_getters::First(key_value, Rank1()), &inner_listener); const std::string explanation = inner_listener.str(); if (!explanation.empty()) { *listener << "whose first field is a value " << explanation; @@ -3087,18 +3088,18 @@ class PairMatcherImpl : public MatcherInterface { if (!listener->IsInterested()) { // If the listener is not interested, we don't need to construct the // explanation. - return first_matcher_.Matches(pair_getters::First(a_pair, Rank0())) && - second_matcher_.Matches(pair_getters::Second(a_pair, Rank0())); + return first_matcher_.Matches(pair_getters::First(a_pair, Rank1())) && + second_matcher_.Matches(pair_getters::Second(a_pair, Rank1())); } StringMatchResultListener first_inner_listener; - if (!first_matcher_.MatchAndExplain(pair_getters::First(a_pair, Rank0()), + if (!first_matcher_.MatchAndExplain(pair_getters::First(a_pair, Rank1()), &first_inner_listener)) { *listener << "whose first field does not match"; PrintIfNotEmpty(first_inner_listener.str(), listener->stream()); return false; } StringMatchResultListener second_inner_listener; - if (!second_matcher_.MatchAndExplain(pair_getters::Second(a_pair, Rank0()), + if (!second_matcher_.MatchAndExplain(pair_getters::Second(a_pair, Rank1()), &second_inner_listener)) { *listener << "whose second field does not match"; PrintIfNotEmpty(second_inner_listener.str(), listener->stream());