summaryrefslogtreecommitdiffstats
path: root/googlemock/include/gmock/gmock-actions.h
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2020-01-09 16:59:39 (GMT)
committerAndy Soffer <asoffer@google.com>2020-01-09 23:25:24 (GMT)
commitc901f67ddf8aab44443f1be3efe864cb3daa95af (patch)
tree19496ce176048d494322e7286bf56724d08d2841 /googlemock/include/gmock/gmock-actions.h
parent8417b7332210322090337d3232e39503437790f0 (diff)
downloadgoogletest-c901f67ddf8aab44443f1be3efe864cb3daa95af.zip
googletest-c901f67ddf8aab44443f1be3efe864cb3daa95af.tar.gz
googletest-c901f67ddf8aab44443f1be3efe864cb3daa95af.tar.bz2
Googletest export
Move part of functionality of Action* class to the base one. Reduce copypaste. Make constructor and conversion operator of Action* class independent of pump. PiperOrigin-RevId: 288907005
Diffstat (limited to 'googlemock/include/gmock/gmock-actions.h')
-rw-r--r--googlemock/include/gmock/gmock-actions.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h
index 11223cf..a7b84d1 100644
--- a/googlemock/include/gmock/gmock-actions.h
+++ b/googlemock/include/gmock/gmock-actions.h
@@ -1222,6 +1222,43 @@ class ActionHelper {
}
};
+// A helper base class needed for implementing the ACTION* macros.
+// Implements constructor and conversion operator for Action.
+//
+// Template specialization for parameterless Action.
+template <typename Derived>
+class ActionImpl {
+ public:
+ ActionImpl() = default;
+
+ template <typename F>
+ operator ::testing::Action<F>() const { // NOLINT(runtime/explicit)
+ return ::testing::Action<F>(new typename Derived::template gmock_Impl<F>());
+ }
+};
+
+// Template specialization for parameterized Action.
+template <template <typename...> class Derived, typename... Ts>
+class ActionImpl<Derived<Ts...>> {
+ public:
+ explicit ActionImpl(Ts... params) : params_(std::forward<Ts>(params)...) {}
+
+ template <typename F>
+ operator ::testing::Action<F>() const { // NOLINT(runtime/explicit)
+ return Apply<F>(MakeIndexSequence<sizeof...(Ts)>{});
+ }
+
+ private:
+ template <typename F, std::size_t... tuple_ids>
+ ::testing::Action<F> Apply(IndexSequence<tuple_ids...>) const {
+ return ::testing::Action<F>(new
+ typename Derived<Ts...>::template gmock_Impl<F>(
+ std::get<tuple_ids>(params_)...));
+ }
+
+ std::tuple<Ts...> params_;
+};
+
namespace invoke_argument {
// Appears in InvokeArgumentAdl's argument list to help avoid