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
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user