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
This commit is contained in:
Abseil Team
2020-08-03 12:33:44 -04:00
committed by Derek Mauro
parent 48ec64092a
commit 5a5caab358
3 changed files with 7 additions and 21 deletions

View File

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