diff --git a/src/util/BindMethod.hxx b/src/util/BindMethod.hxx index 2b95d2e0d..31503bcfc 100644 --- a/src/util/BindMethod.hxx +++ b/src/util/BindMethod.hxx @@ -125,14 +125,16 @@ struct MethodSignatureHelper { }; /** - * Helper class which converts a plain function signature type to a - * wrapper function pointer type. + * Helper class which converts a function pointer to a wrapper + * function pointer type. */ template -struct MethodWrapperWithSignature; +struct FunctionSignatureHelper; template -struct MethodWrapperWithSignature { +struct FunctionSignatureHelper { + typedef R plain_signature(Args...) noexcept(NoExcept); + typedef R (*function_pointer)(void *instance, Args...) noexcept(NoExcept); }; @@ -161,52 +163,27 @@ MakeBindMethodWrapper() noexcept return BindMethodWrapperGenerator::Invoke; } -/** - * Helper class which introspects a function pointer type. - * - * @param S the function type - */ -template -struct FunctionTraits; - -template -struct FunctionTraits { - /** - * A function type which describes the "plain" function - * signature. - */ - typedef R function_type(Args...) noexcept(NoExcept); - - /** - * A function pointer type which describes the "plain" - * function signature. - */ - typedef R (*pointer)(Args...) noexcept(NoExcept); -}; - /** * Generate a wrapper function. * - * @param S the plain function signature type - * @param P the plain function pointer type + * @param F the function pointer type * @param function the function pointer */ -template +template struct BindFunctionWrapperGenerator; template -struct BindFunctionWrapperGenerator { +struct BindFunctionWrapperGenerator { static R Invoke(void *, Args... args) noexcept(NoExcept) { return function(std::forward(args)...); } }; -template -typename MethodWrapperWithSignature::function_pointer +template +typename FunctionSignatureHelper::function_pointer MakeBindFunctionWrapper() noexcept { - return BindFunctionWrapperGenerator::Invoke; + return BindFunctionWrapperGenerator::Invoke; } } /* namespace BindMethodDetail */ @@ -245,15 +222,18 @@ BindMethod(typename BindMethodDetail::MethodSignatureHelper::c /** * Construct a #BoundMethod instance for a plain function. * - * @param T the #FunctionTraits class * @param function the function pointer */ -template -constexpr BoundMethod +template +constexpr auto BindFunction() noexcept { - return BoundMethod(nullptr, - BindMethodDetail::MakeBindFunctionWrapper()); + using H = BindMethodDetail::FunctionSignatureHelper; + using plain_signature = typename H::plain_signature; + return BoundMethod{ + nullptr, + BindMethodDetail::MakeBindFunctionWrapper(), + }; } /** @@ -261,4 +241,4 @@ BindFunction() noexcept * #BoundMethod instance. */ #define BIND_FUNCTION(function) \ - BindFunction, &function>() + BindFunction<&function>()