diff --git a/include/Continuable.h b/include/Continuable.h index ff33a96..ed5f7a8 100644 --- a/include/Continuable.h +++ b/include/Continuable.h @@ -362,7 +362,10 @@ namespace detail template struct functional_traits { - /// Wrap void returning functionals to returns an empty continuable. + /// Wrap void returning functionals to return an empty continuable. + /// Example: + /// void(int, float) to Continuable<>(int, float) + /// TODO Move this into an acceptor helper class. template static auto remove_void_trait(_CTy&& functional) -> typename std::enable_if< @@ -388,6 +391,7 @@ namespace detail } /// Route continuable returning functionals through. + /// TODO Move this into an acceptor helper class. template static auto remove_void_trait(_CTy&& functional) -> typename std::enable_if< @@ -401,7 +405,8 @@ namespace detail return std::forward<_CTy>(functional); } - /// Wrap continuables into the continuable returning functional type. + /// Wrap Continuables into the continuable returning functional type. + /// TODO Move this into an acceptor helper class. template static auto box_continuable_trait(_CTy&& continuable) -> typename std::enable_if< @@ -428,30 +433,43 @@ namespace detail }; } - /// Route functionals through + /// `box_continuable_trait`: Converts plain Continuables to continuable retuning functions. + /// TODO Move this into an acceptor helper class. template - inline static auto box_continuable_trait(_CTy&& continuable) + static auto correct_stage(_CTy&& functional) + -> typename std::enable_if< + detail::is_continuable< + typename std::decay<_CTy>::type + >::value, + decltype(box_continuable_trait(std::declval<_CTy>())) + >::type + { + return box_continuable_trait(std::forward<_CTy>(functional)); + } + + /// `partialize_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 + static auto correct_stage(_CTy&& functional) -> typename std::enable_if< !detail::is_continuable< typename std::decay<_CTy>::type >::value, - typename std::decay<_CTy>::type + decltype(remove_void_trait(std::declval<_CTy>())) >::type { - static_assert(std::is_rvalue_reference<_CTy&&>::value, - "Given continuable must be passed as r-value!"); - - return std::forward<_CTy>(continuable); + return remove_void_trait(std::forward<_CTy>(functional)); } - /// Correct user given continuable functionals. - /// Converts plan continuables to continuable retuning functions. - /// Converts void return to empty continuable. + /// Correct user given functionals through several stages into the form: + /// Continuable<_CArgs...>(_FArgs + /// TODO Move this into an acceptor helper class. template - static auto correct(_CTy&& functional) - -> decltype(remove_void_trait(box_continuable_trait(std::declval<_CTy>()))) + static inline auto correct(_CTy&& functional) + -> decltype(correct_stage(std::declval<_CTy>())) { - return remove_void_trait(box_continuable_trait(std::forward<_CTy>(functional))); + return correct_stage(std::forward<_CTy>(functional)); } template diff --git a/mockup.cpp b/mockup.cpp index a6f328e..1738a7f 100644 --- a/mockup.cpp +++ b/mockup.cpp @@ -148,7 +148,8 @@ void chain_continuable_mockup() void final_mockup() { // Optional - Create a dispatcher where which dispatches the main chain. - auto const my_dispatcher = std::make_shared&&)>>([](std::function&& function) + auto const my_dispatcher = + std::make_shared&&)>>([](std::function&& function) { // Dispatch in same thread or pass to another one function(); @@ -164,7 +165,7 @@ void final_mockup() .then([](std::string github, std::string google, ResultSet user) { // result bla bla - return std::forward_as_tuple(github.empty(), std::move(google), std::move(user)); + return std::make_tuple(github.empty(), std::move(google), std::move(user)); }) .then([](bool hasContent, std::string google, ResultSet user) {