diff --git a/include/Continuable.h b/include/Continuable.h index 876b445..73d76ce 100644 --- a/include/Continuable.h +++ b/include/Continuable.h @@ -101,8 +101,8 @@ namespace detail template struct void_wrap_trait; - template - struct functional_corrector; + template + struct functional_traits; } // detail @@ -221,7 +221,7 @@ public: static_assert(std::is_rvalue_reference<_CTy&&>::value, "Given continuable must be passed as r-value!"); - return then(box_continuable_trait(std::forward<_CTy>(continuable))); + return then(detail::functional_traits<_ATy...>::box_continuable_trait(std::forward<_CTy>(continuable))); } template @@ -327,83 +327,91 @@ inline auto make_continuable() namespace detail { - /// Wrap void returning functionals to returns an empty continuable. template - static auto remove_void_trait(_CTy&& functional) - -> typename std::enable_if< - std::is_void< - fu::return_type_of_t< - typename std::decay<_CTy>::type - > - >::value, - /*decltype( - detail::void_wrap_trait< + struct continuable_traits; + + template + struct continuable_traits> + { + + }; + + /// Continuable processing detail implementation + template + struct functional_traits + { + /// Wrap void returning functionals to returns an empty continuable. + template + static auto remove_void_trait(_CTy&& functional) + -> typename std::enable_if< + std::is_void< fu::return_type_of_t< typename std::decay<_CTy>::type > - >::wrap(std::declval<_CTy>()) - ) - */ - decltype( - detail::functional_corrector<_CTy>::correct(std::declval<_CTy>()) - ) - // std::function()> - >::type - { - /*return detail::void_wrap_trait< - fu::return_type_of_t< - typename std::decay<_CTy>::type - > - >::wrap(std::forward<_CTy>(functional));*/ - return detail::functional_corrector<_CTy>::correct(std::forward<_CTy>(functional)); - } - - /// Route continuable returning functionals through. - /*template - static auto remove_void_trait(_CTy&& functional) - -> typename std::enable_if< - !std::is_void< - fu::return_type_of_t< - typename std::decay<_CTy>::type - > - >::value, - _CTy>::type - { - return std::forward<_CTy>(functional); - }*/ - - /// Wrap continuables into the continuable returning functional type. - template - auto box_continuable_trait(_CTy&& continuable) - -> typename std::enable_if::type>::value, - std::function::type(_ATy...)>>::type - { - // Trick C++11 lambda capture rules for non copyable but moveable continuables. - std::shared_ptr::type> shared_continuable = - std::make_shared::type>(std::forward<_CTy>(continuable)); - - // Create a fake function which returns the value on invoke. - return [shared_continuable](_ATy...) + >::value, + /*decltype( + detail::void_wrap_trait< + fu::return_type_of_t< + typename std::decay<_CTy>::type + > + >::wrap(std::declval<_CTy>()) + ) + */ + decltype( + detail::functional_corrector<_CTy>::correct(std::declval<_CTy>()) + ) + // std::function()> + >::type { - return std::move(*shared_continuable); - }; - } + /*return detail::void_wrap_trait< + fu::return_type_of_t< + typename std::decay<_CTy>::type + > + >::wrap(std::forward<_CTy>(functional));*/ + return detail::functional_corrector<_CTy>::correct(std::forward<_CTy>(functional)); + } - /// Route functionals through and forward to remove_void_trait - template - auto box_continuable_trait(_CTy&& continuable) - -> typename std::enable_if::type>::value, - typename std::decay<_CTy>::type>::type - { - return continuable; - } + /// Route continuable returning functionals through. + /*template + static auto remove_void_trait(_CTy&& functional) + -> typename std::enable_if< + !std::is_void< + fu::return_type_of_t< + typename std::decay<_CTy>::type + > + >::value, + _CTy>::type + { + return std::forward<_CTy>(functional); + }*/ - template - struct functional_corrector - { - typedef fu::return_type_of_t<_CTy> return_t; - typedef fu::argument_type_of_t<_CTy> arg_t; + /// Wrap continuables into the continuable returning functional type. + template + static auto box_continuable_trait(_CTy&& continuable) + -> typename std::enable_if::type>::value, + std::function::type(_ATy...)>>::type + { + // Trick C++11 lambda capture rules for non copyable but moveable continuables. + std::shared_ptr::type> shared_continuable = + std::make_shared::type>(std::forward<_CTy>(continuable)); + // Create a fake function which returns the value on invoke. + return [shared_continuable](_ATy...) + { + return std::move(*shared_continuable); + }; + } + + /// Route functionals through and forward to remove_void_trait + template + static auto box_continuable_trait(_CTy&& continuable) + -> typename std::enable_if::type>::value, + typename std::decay<_CTy>::type>::type + { + return continuable; + } + + template static int correct(_CTy&&) { return 1; diff --git a/test.cpp b/test.cpp index 312c504..cbb9b47 100644 --- a/test.cpp +++ b/test.cpp @@ -230,9 +230,11 @@ int main(int /*argc*/, char** /*argv*/) */ +/* auto testres = Continuable<>::remove_void_trait([] { }); + */ std::cout << "ok" << std::endl; return 0;