diff options
author | Abseil Team <absl-team@google.com> | 2020-01-24 19:09:22 (GMT) |
---|---|---|
committer | Andy Getz <durandal@google.com> | 2020-02-07 18:34:03 (GMT) |
commit | 87061810f4c744cdc1abb8f1cd98970a986eea75 (patch) | |
tree | 1c1c1cd9c86bfef54a7f9a5406ce1bb3377ecd68 /googlemock/include/gmock/gmock-matchers.h | |
parent | f1a6db9d4a8c099d12a2b441b0b85503bdf0dd6e (diff) | |
download | googletest-87061810f4c744cdc1abb8f1cd98970a986eea75.zip googletest-87061810f4c744cdc1abb8f1cd98970a986eea75.tar.gz googletest-87061810f4c744cdc1abb8f1cd98970a986eea75.tar.bz2 |
Googletest export
Move part of functionality of Matcher* class to the base one. Reduce copypaste.
Make constructor and conversion operator of Matcher* class independent of pump.
PiperOrigin-RevId: 291405510
Diffstat (limited to 'googlemock/include/gmock/gmock-matchers.h')
-rw-r--r-- | googlemock/include/gmock/gmock-matchers.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 4baeb1b..f1805db 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -236,6 +236,58 @@ class MatcherCastImpl<T, Matcher<T> > { static Matcher<T> Cast(const Matcher<T>& matcher) { return matcher; } }; +// Template specialization for parameterless Matcher. +template <typename Derived> +class MatcherBaseImpl { + public: + MatcherBaseImpl() = default; + + template <typename T> + operator ::testing::Matcher<T>() const { // NOLINT(runtime/explicit) + return ::testing::Matcher<T>(new + typename Derived::template gmock_Impl<T>()); + } +}; + +// Template specialization for Matcher with 1 parameter. +template <template <typename...> class Derived, typename T> +class MatcherBaseImpl<Derived<T>> { + public: + explicit MatcherBaseImpl(T param) : param_(std::move(param)) {} + + template <typename F> + operator ::testing::Matcher<F>() const { // NOLINT(runtime/explicit) + return ::testing::Matcher<F>( + new typename Derived<T>::template gmock_Impl<F>(param_)); + } + + private: + const T param_; +}; + +// Template specialization for Matcher with multiple parameters. +template <template <typename...> class Derived, typename... Ts> +class MatcherBaseImpl<Derived<Ts...>> { + public: + MatcherBaseImpl(Ts... params) + : params_(std::move(params)...) {} // NOLINT(runtime/explicit) + + template <typename F> + operator ::testing::Matcher<F>() const { // NOLINT(runtime/explicit) + return Apply<F>(MakeIndexSequence<sizeof...(Ts)>{}); + } + + private: + template <typename F, std::size_t... tuple_ids> + ::testing::Matcher<F> Apply(IndexSequence<tuple_ids...>) const { + return ::testing::Matcher<F>( + new typename Derived<Ts...>::template gmock_Impl<F>( + std::get<tuple_ids>(params_)...)); + } + + const std::tuple<Ts...> params_; +}; + } // namespace internal // In order to be safe and clear, casting between different matcher |