diff options
author | ofats <ofats@google.com> | 2020-11-05 11:53:56 -0500 |
---|---|---|
committer | Andy Getz <durandal@google.com> | 2020-11-05 15:07:26 -0500 |
commit | 710f9c11ca79e578bb38d98d10ab9b70d41d5e07 (patch) | |
tree | 8821f5064fee4a1403db13da80ab8ca06106e2c9 /googlemock/include/gmock/gmock-generated-actions.h.pump | |
parent | fb98f7447e5d2e498d6458dcd5c888fdeaae82bc (diff) | |
download | googletest-710f9c11ca79e578bb38d98d10ab9b70d41d5e07.tar.gz googletest-710f9c11ca79e578bb38d98d10ab9b70d41d5e07.zip |
Googletest export
Rewrite InvokeArgument action without using pump.
PiperOrigin-RevId: 340861582
Diffstat (limited to 'googlemock/include/gmock/gmock-generated-actions.h.pump')
-rw-r--r-- | googlemock/include/gmock/gmock-generated-actions.h.pump | 56 |
1 files changed, 38 insertions, 18 deletions
diff --git a/googlemock/include/gmock/gmock-generated-actions.h.pump b/googlemock/include/gmock/gmock-generated-actions.h.pump index 7a7fc9f4..0bdb42e6 100644 --- a/googlemock/include/gmock/gmock-generated-actions.h.pump +++ b/googlemock/include/gmock/gmock-generated-actions.h.pump @@ -305,10 +305,8 @@ $range k 0..n-1 gmock_PerformImpl(\ GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - namespace testing { - // The ACTION*() macros trigger warning C4100 (unreferenced formal // parameter) in MSVC with -W4. Unfortunately they cannot be fixed in // the macro definition, as the warnings are generated when the macro @@ -319,8 +317,36 @@ namespace testing { # pragma warning(disable:4100) #endif -// Various overloads for InvokeArgument<N>(). -// +namespace internal { + +// internal::InvokeArgument - a helper for InvokeArgument action. +// The basic overloads are provided here for generic functors. +// Overloads for other custom-callables are provided in the +// internal/custom/gmock-generated-actions.h header. +template <typename F, typename... Args> +auto InvokeArgument(F f, Args... args) -> decltype(f(args...)) { + return f(args...); +} + +template <std::size_t index, typename... Params> +struct InvokeArgumentAction { + template <typename... Args> + auto operator()(Args&&... args) const -> decltype(internal::InvokeArgument( + std::get<index>(std::forward_as_tuple(std::forward<Args>(args)...)), + std::declval<const Params&>()...)) { + internal::FlatTuple<Args&&...> args_tuple(std::forward<Args>(args)...); + return params.Apply([&](const Params&... unpacked_params) { + auto&& callable = args_tuple.template Get<index>(); + return internal::InvokeArgument( + std::forward<decltype(callable)>(callable), unpacked_params...); + }); + } + + internal::FlatTuple<Params...> params; +}; + +} // namespace internal + // The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th // (0-based) argument, which must be a k-ary callable, of the mock // function, with arguments a1, a2, ..., a_k. @@ -328,15 +354,15 @@ namespace testing { // Notes: // // 1. The arguments are passed by value by default. If you need to -// pass an argument by reference, wrap it inside ByRef(). For +// pass an argument by reference, wrap it inside std::ref(). For // example, // -// InvokeArgument<1>(5, string("Hello"), ByRef(foo)) +// InvokeArgument<1>(5, string("Hello"), std::ref(foo)) // // passes 5 and string("Hello") by value, and passes foo by // reference. // -// 2. If the callable takes an argument by reference but ByRef() is +// 2. If the callable takes an argument by reference but std::ref() is // not used, it will receive the reference to a copy of the value, // instead of the original value. For example, when the 0-th // argument of the mock function takes a const string&, the action @@ -348,19 +374,13 @@ namespace testing { // to the callable. This makes it easy for a user to define an // InvokeArgument action from temporary values and have it performed // later. - -$range i 0..n -$for i [[ -$range j 0..i-1 - -ACTION_TEMPLATE(InvokeArgument, - HAS_1_TEMPLATE_PARAMS(int, k), - AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]])) { - return internal::InvokeArgument(::std::get<k>(args)$for j[[, p$j]]); +template <std::size_t index, typename... Params> +internal::InvokeArgumentAction<index, typename std::decay<Params>::type...> +InvokeArgument(Params&&... params) { + return {internal::FlatTuple<typename std::decay<Params>::type...>( + std::forward<Params>(params)...)}; } -]] - #ifdef _MSC_VER # pragma warning(pop) #endif |