diff --git a/Incubator.cpp b/Incubator.cpp index fbddda5..7be89ec 100644 --- a/Incubator.cpp +++ b/Incubator.cpp @@ -703,58 +703,7 @@ 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 089add7..1e3cf4a 100644 --- a/include/Continuable.h +++ b/include/Continuable.h @@ -358,6 +358,50 @@ namespace detail typedef Tuple tuple; }; + /// Corrects functionals with non expected signatures + /// to match the expected ones. + /// Used in `partialize_correct_trait` + 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); + } + }; + /// Continuable processing detail implementation template struct functional_traits @@ -405,6 +449,15 @@ namespace detail return std::forward<_CTy>(functional); } + template + static inline auto partialize_correct_trait(_CTy&& functional) + // -> decltype(partial_corrector<_ATy>::correct(std::declval<_CTy>())) + -> _CTy + { + // return partial_corrector<_ATy>::correct(std::forward<_CTy>(functional)); + return std::forward<_CTy>(functional); + } + /// Wrap Continuables into the continuable returning functional type. /// TODO Move this into an acceptor helper class. template @@ -447,7 +500,7 @@ namespace detail return box_continuable_trait(std::forward<_CTy>(functional)); } - /// `partialize_trait`: Converts functionals with not matching args signature. + /// `partialize_correct_trait`: Converts functionals with not matching args signature. /// `remove_void_trait`: Converts void return to empty continuable. /// TODO Move this into an acceptor helper class. template @@ -456,10 +509,10 @@ namespace detail !detail::is_continuable< typename std::decay<_CTy>::type >::value, - decltype(remove_void_trait(std::declval<_CTy>())) + decltype(remove_void_trait(partialize_correct_trait(std::declval<_CTy>()))) >::type { - return remove_void_trait(std::forward<_CTy>(functional)); + return remove_void_trait(partialize_correct_trait(std::forward<_CTy>(functional))); } /// Correct user given functionals through several stages into the form: