Set up inlining for InvokeWithoutArgs when passed a functor.

Actions can now be implicitly constructed from zero-argument callables. There is no need to create wrapper objects using InvokeWithoutArgs().

PiperOrigin-RevId: 949656497
Change-Id: Ida2bc38e446e7b33aaf185ec593caf2a1959138e
This commit is contained in:
Abseil Team
2026-07-17 10:58:22 -07:00
committed by Copybara-Service
parent 4141c384aa
commit fa005b296f
3 changed files with 10 additions and 25 deletions
+5 -19
View File
@@ -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<F> as long as f's type is compatible with F.
template <typename FunctionImpl>
struct InvokeWithoutArgsAction {
FunctionImpl function_impl;
// Allows InvokeWithoutArgs(f) to be used as any action whose type is
// compatible with f.
template <typename... Args>
auto operator()(const Args&...) -> decltype(function_impl()) {
return function_impl();
}
};
// Implements the InvokeWithoutArgs(object_ptr, &Class::Method) action.
template <class Class, typename MethodPtr>
struct InvokeMethodWithoutArgsAction {
@@ -2070,9 +2054,11 @@ internal::InvokeMethodAction<Class, MethodPtr> Invoke(Class* obj_ptr,
// Creates an action that invokes 'function_impl' with no argument.
template <typename FunctionImpl>
internal::InvokeWithoutArgsAction<typename std::decay<FunctionImpl>::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<FunctionImpl> InvokeWithoutArgs(FunctionImpl&& function_impl) {
return std::forward<FunctionImpl>(function_impl);
}
// Creates an action that invokes the given method on the given object