diff options
| author | Abseil Team <absl-team@google.com> | 2020-08-17 12:07:02 -0400 |
|---|---|---|
| committer | vslashg <gfalcon@google.com> | 2020-08-23 23:50:54 -0400 |
| commit | fc1e7788993bd1418f80d64eb430bd9ac023db68 (patch) | |
| tree | 635927e3cece061c1c042d90c1ef71f32b0b8098 /googlemock/include | |
| parent | adeef192947fbc0f68fa14a6c494c8df32177508 (diff) | |
| download | googletest-fc1e7788993bd1418f80d64eb430bd9ac023db68.tar.gz googletest-fc1e7788993bd1418f80d64eb430bd9ac023db68.zip | |
Googletest export
Fix DoAll to work with move-only sink arguments.
This changes types of the first n - 1 actions so that they only get a readonly
view of the arguments. The last action will accept move only objects.
PiperOrigin-RevId: 327031893
Diffstat (limited to 'googlemock/include')
| -rw-r--r-- | googlemock/include/gmock/gmock-actions.h | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index 79054dbc..3aba9ec0 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -1032,9 +1032,13 @@ struct WithArgsAction { template <typename... Actions> struct DoAllAction { private: - template <typename... Args, size_t... I> - std::vector<Action<void(Args...)>> Convert(IndexSequence<I...>) const { - return {std::get<I>(actions)...}; + template <typename T> + using NonFinalType = + typename std::conditional<std::is_scalar<T>::value, T, const T&>::type; + + template <typename ActionT, size_t... I> + std::vector<ActionT> Convert(IndexSequence<I...>) const { + return {ActionT(std::get<I>(actions))...}; } public: @@ -1043,17 +1047,17 @@ struct DoAllAction { template <typename R, typename... Args> operator Action<R(Args...)>() const { // NOLINT struct Op { - std::vector<Action<void(Args...)>> converted; + std::vector<Action<void(NonFinalType<Args>...)>> converted; Action<R(Args...)> last; R operator()(Args... args) const { - auto tuple_args = std::forward_as_tuple(std::forward<Args>(args)...); for (auto& a : converted) { - a.Perform(tuple_args); + a.Perform(std::forward_as_tuple(std::forward<Args>(args)...)); } - return last.Perform(tuple_args); + return last.Perform(std::forward_as_tuple(std::forward<Args>(args)...)); } }; - return Op{Convert<Args...>(MakeIndexSequence<sizeof...(Actions) - 1>()), + return Op{Convert<Action<void(NonFinalType<Args>...)>>( + MakeIndexSequence<sizeof...(Actions) - 1>()), std::get<sizeof...(Actions) - 1>(actions)}; } }; @@ -1093,7 +1097,8 @@ struct DoAllAction { typedef internal::IgnoredValue Unused; // Creates an action that does actions a1, a2, ..., sequentially in -// each invocation. +// each invocation. All but the last action will have a readonly view of the +// arguments. template <typename... Action> internal::DoAllAction<typename std::decay<Action>::type...> DoAll( Action&&... action) { |

