From dddb219c3eb96d7f9200f09b0a381f016e6b4562 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 28 Dec 2023 04:03:13 -0800 Subject: Accept move-only callables in `InvokeArguments` PiperOrigin-RevId: 594223533 Change-Id: I491fae7d851d4e0df07fb3627416949071fec8d6 --- googlemock/include/gmock/gmock-more-actions.h | 2 +- googlemock/test/gmock-more-actions_test.cc | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/googlemock/include/gmock/gmock-more-actions.h b/googlemock/include/gmock/gmock-more-actions.h index 40300766..dd90e31f 100644 --- a/googlemock/include/gmock/gmock-more-actions.h +++ b/googlemock/include/gmock/gmock-more-actions.h @@ -606,7 +606,7 @@ struct InvokeArgumentAction { internal::FlatTuple args_tuple(FlatTupleConstructTag{}, std::forward(args)...); return params.Apply([&](const Params &...unpacked_params) { - auto &&callable = args_tuple.template Get(); + auto &&callable = std::move(args_tuple.template Get()); return internal::InvokeArgument( std::forward(callable), unpacked_params...); }); diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc index 9980f3bc..16af6892 100644 --- a/googlemock/test/gmock-more-actions_test.cc +++ b/googlemock/test/gmock-more-actions_test.cc @@ -85,6 +85,12 @@ struct UnaryFunctor { int operator()(bool x) { return x ? 1 : -1; } }; +struct UnaryMoveOnlyFunctor : UnaryFunctor { + UnaryMoveOnlyFunctor() = default; + UnaryMoveOnlyFunctor(const UnaryMoveOnlyFunctor&) = delete; + UnaryMoveOnlyFunctor(UnaryMoveOnlyFunctor&&) = default; +}; + const char* Binary(const char* input, short n) { return input + n; } // NOLINT int Ternary(int x, char y, short z) { return x + y + z; } // NOLINT @@ -698,12 +704,18 @@ TEST(InvokeArgumentTest, Function0) { EXPECT_EQ(1, a.Perform(std::make_tuple(2, &Nullary))); } -// Tests using InvokeArgument with a unary function. +// Tests using InvokeArgument with a unary functor. TEST(InvokeArgumentTest, Functor1) { Action a = InvokeArgument<0>(true); // NOLINT EXPECT_EQ(1, a.Perform(std::make_tuple(UnaryFunctor()))); } +// Tests using InvokeArgument with a unary move-only functor. +TEST(InvokeArgumentTest, Functor1MoveOnly) { + Action a = InvokeArgument<0>(true); // NOLINT + EXPECT_EQ(1, a.Perform(std::make_tuple(UnaryMoveOnlyFunctor()))); +} + // Tests using InvokeArgument with a 5-ary function. TEST(InvokeArgumentTest, Function5) { Action a = // NOLINT -- cgit v1.2.3