Skip to content

Commit dddb219

Browse files
Abseil Teamcopybara-github
authored andcommitted
Accept move-only callables in InvokeArguments
PiperOrigin-RevId: 594223533 Change-Id: I491fae7d851d4e0df07fb3627416949071fec8d6
1 parent 96eadf6 commit dddb219

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

googlemock/include/gmock/gmock-more-actions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ struct InvokeArgumentAction {
606606
internal::FlatTuple<Args &&...> args_tuple(FlatTupleConstructTag{},
607607
std::forward<Args>(args)...);
608608
return params.Apply([&](const Params &...unpacked_params) {
609-
auto &&callable = args_tuple.template Get<index>();
609+
auto &&callable = std::move(args_tuple.template Get<index>());
610610
return internal::InvokeArgument(
611611
std::forward<decltype(callable)>(callable), unpacked_params...);
612612
});

googlemock/test/gmock-more-actions_test.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ struct UnaryFunctor {
8585
int operator()(bool x) { return x ? 1 : -1; }
8686
};
8787

88+
struct UnaryMoveOnlyFunctor : UnaryFunctor {
89+
UnaryMoveOnlyFunctor() = default;
90+
UnaryMoveOnlyFunctor(const UnaryMoveOnlyFunctor&) = delete;
91+
UnaryMoveOnlyFunctor(UnaryMoveOnlyFunctor&&) = default;
92+
};
93+
8894
const char* Binary(const char* input, short n) { return input + n; } // NOLINT
8995

9096
int Ternary(int x, char y, short z) { return x + y + z; } // NOLINT
@@ -698,12 +704,18 @@ TEST(InvokeArgumentTest, Function0) {
698704
EXPECT_EQ(1, a.Perform(std::make_tuple(2, &Nullary)));
699705
}
700706

701-
// Tests using InvokeArgument with a unary function.
707+
// Tests using InvokeArgument with a unary functor.
702708
TEST(InvokeArgumentTest, Functor1) {
703709
Action<int(UnaryFunctor)> a = InvokeArgument<0>(true); // NOLINT
704710
EXPECT_EQ(1, a.Perform(std::make_tuple(UnaryFunctor())));
705711
}
706712

713+
// Tests using InvokeArgument with a unary move-only functor.
714+
TEST(InvokeArgumentTest, Functor1MoveOnly) {
715+
Action<int(UnaryMoveOnlyFunctor)> a = InvokeArgument<0>(true); // NOLINT
716+
EXPECT_EQ(1, a.Perform(std::make_tuple(UnaryMoveOnlyFunctor())));
717+
}
718+
707719
// Tests using InvokeArgument with a 5-ary function.
708720
TEST(InvokeArgumentTest, Function5) {
709721
Action<int(int (*)(int, int, int, int, int))> a = // NOLINT

0 commit comments

Comments
 (0)