diff options
author | Abseil Team <absl-team@google.com> | 2020-08-03 16:33:44 (GMT) |
---|---|---|
committer | Derek Mauro <dmauro@google.com> | 2020-08-07 17:08:00 (GMT) |
commit | 5a5caab358c2c7059adef1acb22f6cab907b888d (patch) | |
tree | fb0495e346dd9f717be4e05fe45a3086b6cf283f /googlemock/include/gmock/gmock-actions.h | |
parent | 48ec64092a38621210ecd835fde61d76861269c1 (diff) | |
download | googletest-5a5caab358c2c7059adef1acb22f6cab907b888d.zip googletest-5a5caab358c2c7059adef1acb22f6cab907b888d.tar.gz googletest-5a5caab358c2c7059adef1acb22f6cab907b888d.tar.bz2 |
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: 324619666
Diffstat (limited to 'googlemock/include/gmock/gmock-actions.h')
-rw-r--r-- | googlemock/include/gmock/gmock-actions.h | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index 4f7c1dd..79054db 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -1032,13 +1032,8 @@ struct WithArgsAction { template <typename... Actions> struct DoAllAction { private: - template <typename T> - using NonFinalType = - typename std::conditional<std::is_scalar<T>::value, T, const T&>::type; - template <typename... Args, size_t... I> - std::vector<Action<void(NonFinalType<Args>...)>> Convert( - IndexSequence<I...>) const { + std::vector<Action<void(Args...)>> Convert(IndexSequence<I...>) const { return {std::get<I>(actions)...}; } @@ -1048,13 +1043,14 @@ struct DoAllAction { template <typename R, typename... Args> operator Action<R(Args...)>() const { // NOLINT struct Op { - std::vector<Action<void(NonFinalType<Args>...)>> converted; + std::vector<Action<void(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(std::forward_as_tuple(std::forward<Args>(args)...)); + a.Perform(tuple_args); } - return last.Perform(std::forward_as_tuple(std::forward<Args>(args)...)); + return last.Perform(tuple_args); } }; return Op{Convert<Args...>(MakeIndexSequence<sizeof...(Actions) - 1>()), @@ -1097,8 +1093,7 @@ struct DoAllAction { typedef internal::IgnoredValue Unused; // Creates an action that does actions a1, a2, ..., sequentially in -// each invocation. All but the last action will have a readonly view of the -// arguments. +// each invocation. template <typename... Action> internal::DoAllAction<typename std::decay<Action>::type...> DoAll( Action&&... action) { |