From f4a148acbe0c3fe439e21719e19cd3233f10d613 Mon Sep 17 00:00:00 2001 From: Michael Tsukanov Date: Thu, 13 Mar 2025 22:59:50 +0300 Subject: [PATCH] Initial deduction guides impl --- include/function2/function2.hpp | 68 ++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 9 deletions(-) diff --git a/include/function2/function2.hpp b/include/function2/function2.hpp index ffb82b5..822da43 100644 --- a/include/function2/function2.hpp +++ b/include/function2/function2.hpp @@ -1779,20 +1779,70 @@ using function_base = detail::function< detail::config, detail::property>; -/// An owning copyable function wrapper for arbitrary callable types. +/// An owning copyable function wrapper. template -using function = function_base; +struct function : public function_base { + using base = function_base; + using base::base; +}; -/// An owning non copyable function wrapper for arbitrary callable types. +/// An owning non-copyable function wrapper. template -using unique_function = function_base; +struct unique_function : public function_base { + using base = function_base; + using base::base; +}; -/// A non owning copyable function wrapper for arbitrary callable types. +/// A non-owning copyable function wrapper. template -using function_view = function_base; +struct function_view : public function_base { + using base = function_base; + using base::base; +}; + +// Helper to decompose member function pointer types +template +struct function_traits; + +template +struct function_traits { + using signature = R(Args...); +}; + +template +struct function_traits { + using signature = R(Args...); +}; + +// Deduce the signature for a callable F +template +struct deduce_signature {}; + +// Handle function pointers +template +struct deduce_signature { + using type = R(Args...); +}; + +// Handle functors (lambdas, objects with operator()) +template +struct deduce_signature> { +private: + using call_operator_t = decltype(&F::operator()); + using traits = function_traits; +public: + using type = typename traits::signature; +}; + +// Deduction guides for each wrapper +template +function(F) -> function::type>; + +template +unique_function(F) -> unique_function::type>; + +template +function_view(F) -> function_view::type>; #if !defined(FU2_HAS_DISABLED_EXCEPTIONS) /// Exception type that is thrown when invoking empty function objects