Googletest export

Rewrite ReturnNew action without using pump.

PiperOrigin-RevId: 308219616
This commit is contained in:
Abseil Team
2020-04-24 05:17:47 -04:00
committed by Gennadiy Rozental
parent d7ca9af004
commit 955552518b
6 changed files with 104 additions and 175 deletions

View File

@@ -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