diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index 94552cea2..687da5ccc 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -1331,22 +1331,6 @@ struct InvokeMethodAction { } }; -// Implements the InvokeWithoutArgs(f) action. The template argument -// FunctionImpl is the implementation type of f, which can be either a -// function pointer or a functor. InvokeWithoutArgs(f) can be used as an -// Action as long as f's type is compatible with F. -template -struct InvokeWithoutArgsAction { - FunctionImpl function_impl; - - // Allows InvokeWithoutArgs(f) to be used as any action whose type is - // compatible with f. - template - auto operator()(const Args&...) -> decltype(function_impl()) { - return function_impl(); - } -}; - // Implements the InvokeWithoutArgs(object_ptr, &Class::Method) action. template struct InvokeMethodWithoutArgsAction { @@ -2070,9 +2054,11 @@ internal::InvokeMethodAction Invoke(Class* obj_ptr, // Creates an action that invokes 'function_impl' with no argument. template -internal::InvokeWithoutArgsAction::type> -InvokeWithoutArgs(FunctionImpl function_impl) { - return {std::move(function_impl)}; +GTEST_INTERNAL_DEPRECATE_AND_INLINE( + "Actions can now be implicitly constructed from zero-argument callables. " + "No need to create wrapper objects using InvokeWithoutArgs().") +std::decay_t InvokeWithoutArgs(FunctionImpl&& function_impl) { + return std::forward(function_impl); } // Creates an action that invokes the given method on the given object diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 507db6b2a..0a0334964 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -1223,15 +1223,15 @@ class Foo { // Tests InvokeWithoutArgs(function). TEST(InvokeWithoutArgsTest, Function) { // As an action that takes one argument. - Action a = InvokeWithoutArgs(Nullary); // NOLINT + Action a = Nullary; // NOLINT EXPECT_EQ(1, a.Perform(std::make_tuple(2))); // As an action that takes two arguments. - Action a2 = InvokeWithoutArgs(Nullary); // NOLINT + Action a2 = Nullary; // NOLINT EXPECT_EQ(1, a2.Perform(std::make_tuple(2, 3.5))); // As an action that returns void. - Action a3 = InvokeWithoutArgs(VoidNullary); // NOLINT + Action a3 = VoidNullary; // NOLINT g_done = false; a3.Perform(std::make_tuple(1)); EXPECT_TRUE(g_done); diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc index 7c51b782f..efe2a528e 100644 --- a/googlemock/test/gmock-more-actions_test.cc +++ b/googlemock/test/gmock-more-actions_test.cc @@ -1026,9 +1026,8 @@ TEST(DoAllTest, NoArgs) { TEST(DoAllTest, MoveOnlyArgs) { bool ran_first = false; - Action)> a = - DoAll(InvokeWithoutArgs([&] { ran_first = true; }), - [](std::unique_ptr p) { return *p; }); + Action)> a = DoAll( + [&] { ran_first = true; }, [](std::unique_ptr p) { return *p; }); EXPECT_EQ(7, a.Perform(std::make_tuple(std::unique_ptr(new int(7))))); EXPECT_TRUE(ran_first); }