diff options
Diffstat (limited to 'googlemock/include/gmock/gmock-actions.h')
-rw-r--r-- | googlemock/include/gmock/gmock-actions.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index 615651b3..1db98d7b 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -138,6 +138,7 @@ #include <functional> #include <memory> #include <string> +#include <tuple> #include <type_traits> #include <utility> @@ -1311,6 +1312,31 @@ inline ::std::reference_wrapper<T> ByRef(T& l_value) { // NOLINT namespace internal { +template <typename T, typename... Params> +struct ReturnNewAction { + T* operator()() const { + return internal::Apply( + [](const Params&... unpacked_params) { + return new T(unpacked_params...); + }, + params); + } + std::tuple<Params...> params; +}; + +} // namespace internal + +// The ReturnNew<T>(a1, a2, ..., a_k) action returns a pointer to a new +// instance of type T, constructed on the heap with constructor arguments +// a1, a2, ..., and a_k. The caller assumes ownership of the returned value. +template <typename T, typename... Params> +internal::ReturnNewAction<T, typename std::decay<Params>::type...> ReturnNew( + Params&&... params) { + return {std::forward_as_tuple(std::forward<Params>(params)...)}; +} + +namespace internal { + // A macro from the ACTION* family (defined later in gmock-generated-actions.h) // defines an action that can be used in a mock function. Typically, // these actions only care about a subset of the arguments of the mock |