diff --git a/include/Continuable.h b/include/Continuable.h index c37fd14..f06fa70 100644 --- a/include/Continuable.h +++ b/include/Continuable.h @@ -76,26 +76,6 @@ namespace detail typedef typename result_t::CallbackFunction callback_t; }; - /// Wrap void returning functionals to returns an empty continuable. - template - auto remove_void_trait(_CTy&& functional) - -> typename std::enable_if::type>>::value, - int>::type - { - return 1; - } - - /// Route continuable returning functionals through. - template - auto remove_void_trait(_CTy&& functional) - -> typename std::enable_if::type>>::value, - _CTy&&>::type - { - return std::forward<_CTy>(functional); - } - template struct multiple_all_chainer { @@ -173,6 +153,30 @@ namespace detail using continuable_factory_t = ContinuableFactory< ::fu::return_type_of_t<_FTy>, ::fu::argument_type_of_t<_FTy>>; + template + struct void_wrap_trait; + + template + struct void_wrap_trait> + { + template + static std::function(Args...)> wrap(_CTy&& functional) + { + return [functional](Args... args) + { + // Invoke the original callback + functional(std::forward(args)...); + + // FIXME return make_empty_continuable() + // Return a fake continuable + return Continuable<>([](Callback<>&& callback) + { + callback(); + }); + }; + } + }; + } // detail template @@ -186,7 +190,7 @@ public: typedef Callback<_ATy...> CallbackFunction; typedef std::function&&)> ForwardFunction; -private: +// private: /// Functional which expects a callback that is inserted from the Continuable /// to chain everything together ForwardFunction _callback_insert; @@ -206,9 +210,48 @@ private: } } - // Pack a continuable into the continuable returning functional type. + /// 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( + void_wrap_trait< + fu::return_type_of_t< + typename std::decay<_CTy>::type + > + >::wrap(std::declval<_CTy>()) + ) + >::type + { + return detail::void_wrap_trait< + fu::return_type_of_t< + typename std::decay<_CTy>::type + > + >::wrap(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 - static auto box_continuable(_CTy&& continuable) + static auto box_continuable_trait(_CTy&& continuable) -> typename std::enable_if::type>::value, std::function::type(_ATy...)>>::type { @@ -223,9 +266,9 @@ private: }; } - // Do nothing if already a non continuable type + /// Route functionals through and forward to remove_void_trait template - static auto box_continuable(_CTy&& continuable) + static auto box_continuable_trait(_CTy&& continuable) -> typename std::enable_if::type>::value, typename std::decay<_CTy>::type>::type { @@ -314,7 +357,7 @@ public: static_assert(std::is_rvalue_reference<_CTy&&>::value, "Given continuable must be passed as r-value!"); - return then(box_continuable(std::forward<_CTy>(continuable))); + return then(box_continuable_trait(std::forward<_CTy>(continuable))); } template @@ -366,6 +409,11 @@ public: */ }; +namespace detail +{ + +} + /// Wraps a functional object which expects a r-value callback as argument into a continuable. /// The callable is invoked when the continuable shall continue. /// For example: diff --git a/test.cpp b/test.cpp index a3b9b96..545d18c 100644 --- a/test.cpp +++ b/test.cpp @@ -222,7 +222,17 @@ int main(int /*argc*/, char** /*argv*/) //// Here we go //entry(); - +/* + auto testaiasj = remove_void_trait([] + { + + }); + + */ + + Continuable<>::remove_void_trait([] + { + }); std::cout << "ok" << std::endl; return 0;