diff --git a/Incubator.cpp b/Incubator.cpp index 7be89ec..fbddda5 100644 --- a/Incubator.cpp +++ b/Incubator.cpp @@ -703,7 +703,58 @@ void test_cross_forward() ++i; } +/// Corrects functionals with non expected signatures +/// to match the expected ones. +template +struct partial_corrector +{ + /// Corrector + template + static auto correct(_CTy&& functional) + -> typename std::enable_if< + !std::is_same< + fu::argument_type_of_t< + typename std::decay<_CTy>::type + >, + fu::identity<_ATy...> + >::value, + std::function< + fu::return_type_of_t< + typename std::decay<_CTy>::type + >(_ATy...) + > + >::type + { + // Make use of std::bind's signature erasure + return std::bind(std::forward<_CTy>(functional)); + } + + // Route through + template + static auto correct(_CTy&& functional) + -> typename std::enable_if< + std::is_same< + fu::argument_type_of_t< + typename std::decay<_CTy>::type + >, + fu::identity<_ATy...> + >::value, + _CTy + >::type + { + return std::forward<_CTy>(functional); + } +}; + void test_incubator() { test_cross_forward(); + + std::function fn1 = partial_corrector::correct([](int, float) + { + }); + + std::function fn2 = partial_corrector::correct([] + { + }); } diff --git a/include/Continuable.h b/include/Continuable.h index ed5f7a8..089add7 100644 --- a/include/Continuable.h +++ b/include/Continuable.h @@ -463,7 +463,7 @@ namespace detail } /// Correct user given functionals through several stages into the form: - /// Continuable<_CArgs...>(_FArgs + /// Continuable<_CArgs...>(_FArgs) /// TODO Move this into an acceptor helper class. template static inline auto correct(_CTy&& functional)