From 26dc37bd7685351fd24fcaec0f83d9b5a8ee0f06 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 3 Dec 2021 08:06:57 +0100 Subject: [PATCH] util/BindMethod: merge structs {Method,Function}WrapperGenerator into one --- src/util/BindMethod.hxx | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/util/BindMethod.hxx b/src/util/BindMethod.hxx index 2f2ca18a5..12fa7356a 100644 --- a/src/util/BindMethod.hxx +++ b/src/util/BindMethod.hxx @@ -124,48 +124,39 @@ struct FunctionSignatureHelper { /** * Generate a wrapper function. * - * @param method the method pointer + * @param method the method/function pointer */ template -struct BindMethodWrapperGenerator; +struct WrapperGenerator; template -struct BindMethodWrapperGenerator { +struct WrapperGenerator { static R Invoke(void *_instance, Args... args) noexcept(NoExcept) { auto &t = *(T *)_instance; return (t.*method)(std::forward(args)...); } }; +template +struct WrapperGenerator { + static R Invoke(void *, Args... args) noexcept(NoExcept) { + return function(std::forward(args)...); + } +}; + template typename MethodSignatureHelper::function_pointer MakeBindMethodWrapper() noexcept { - return BindMethodWrapperGenerator::Invoke; + return WrapperGenerator::Invoke; } -/** - * Generate a wrapper function. - * - * @param F the function pointer type - * @param function the function pointer - */ -template -struct BindFunctionWrapperGenerator; - -template -struct BindFunctionWrapperGenerator { - static R Invoke(void *, Args... args) noexcept(NoExcept) { - return function(std::forward(args)...); - } -}; - template typename FunctionSignatureHelper::function_pointer MakeBindFunctionWrapper() noexcept { - return BindFunctionWrapperGenerator::Invoke; + return WrapperGenerator::Invoke; } } /* namespace BindMethodDetail */