diff --git a/Incubator.cpp b/Incubator.cpp index 579db4c..cadf441 100644 --- a/Incubator.cpp +++ b/Incubator.cpp @@ -583,7 +583,7 @@ void some_examples() */ make_continuable() - .all( + /*.all( CastSpellPromise(10) .then(CastSpellPromise(15)), CastSpellPromise(20), @@ -594,13 +594,17 @@ void some_examples() [] { return TrivialPromise(); }) - .then([](SpellCastResult r0, SpellCastResult r1, bool r2, bool r3, double r4, std::unique_ptr message) + */ + /*.then([](SpellCastResult r0, SpellCastResult r1, bool r2, bool r3, double r4, std::unique_ptr message) { return TrivialPromise("Lets see... ").then(Log(*message)); - }) + })*/ .then([] { return Log("ok, now its really finished!").then(CastSpellPromise(2)); + }) + .then([](SpellCastResult) + { }); // DispatcherPool countPool(1); diff --git a/include/Continuable.h b/include/Continuable.h index 2ae9706..b818667 100644 --- a/include/Continuable.h +++ b/include/Continuable.h @@ -56,21 +56,11 @@ namespace detail } }; + template + struct continuable_acceptor; + template - struct unary_chainer_t; - - template - struct multiple_when_all_chainer_t; - - template - class multiple_result_storage_t; - - template - struct multiple_result_storage_invoker_t; - - /// Functional traits forward declaration. - template - struct functional_traits; + struct continuable_unwrap; } // detail @@ -83,9 +73,6 @@ class Continuable template friend class Continuable; - template - friend struct detail::multiple_result_storage_invoker_t; - public: typedef Callback<_ATy...> CallbackFunction; typedef std::function&&)> ForwardFunction; @@ -112,7 +99,6 @@ private: } public: - /// Deleted copy construct Continuable(Continuable const&) = delete; @@ -165,30 +151,29 @@ public: /// Waits for this continuable and invokes the given callback. template auto then(_CTy&& functional) - -> typename detail::unary_chainer_t<_CTy, _ATy...>::continuable_t + -> typename detail::continuable_unwrap<_CTy, _ATy...>::continuable_t { static_assert(std::is_same, - typename detail::unary_chainer_t<_CTy, _ATy...>::arguments_t>::value, + typename detail::continuable_unwrap<_CTy, _ATy...>::arguments_t>::value, "Given function signature isn't correct, for now it must match strictly!"); ForwardFunction&& callback = std::move(_callback_insert); - auto&& corrected = detail::functional_traits<_ATy...>:: - correct(std::forward<_CTy>(functional)); + auto&& corrected = detail::continuable_acceptor<_ATy...>::accept(std::forward<_CTy>(functional)); - return typename detail::unary_chainer_t<_CTy, _ATy...>::continuable_t( - [corrected, callback](typename detail::unary_chainer_t<_CTy, _ATy...>::callback_t&& call_next) + return typename detail::continuable_unwrap<_CTy, _ATy...>::continuable_t( + [corrected, callback](typename detail::continuable_unwrap<_CTy, _ATy...>::callback_t&& call_next) { callback([corrected, call_next](_ATy&&... args) mutable { // Invoke the next callback - corrected(std::forward<_ATy>(args)...) - .invoke(std::move(call_next)); + corrected(std::forward<_ATy>(args)...).invoke(std::move(call_next)); }); }, std::move(*this)); } + /* template auto all(_CTy&&... functionals) -> typename detail::multiple_when_all_chainer_t< @@ -219,7 +204,6 @@ public: return some(1, std::forward<_CTy>(functionals)...); } - /* /// Validates the Continuable inline Continuable Validate() { @@ -290,23 +274,6 @@ inline auto make_continuable() namespace detail { - /// Helper trait for unary chains like `Continuable::then` - template - struct unary_chainer_t - { - // Corrected user given functional - typedef decltype(detail::functional_traits<_ATy...>:: - correct(std::declval::type>())) corrected_t; - - typedef fu::return_type_of_t continuable_t; - - typedef fu::argument_type_of_t arguments_t; - - typedef typename continuable_t::CallbackFunction callback_t; - - typedef fu::argument_type_of_t callback_arguments_t; - }; - template struct concat_identities; @@ -346,18 +313,6 @@ namespace detail } }; - /// Position wrapper class to pass ints as type - template - struct partial_result - { - enum my_size : std::size_t - { - size = Position - }; - - typedef Tuple tuple; - }; - /// Corrects functionals with non expected signatures /// to match the expected ones. /// Used in `partialize_correct_trait` @@ -402,14 +357,12 @@ namespace detail } }; - /// Continuable processing detail implementation template - struct functional_traits + struct continuable_acceptor { /// 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< @@ -435,7 +388,6 @@ 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< @@ -451,13 +403,13 @@ namespace detail template static inline auto partialize_correct_trait(_CTy&& functional) - -> decltype(partial_corrector<_ATy...>::correct(std::declval<_CTy>())) + -> _CTy// decltype(partial_corrector<_ATy...>::correct(std::declval<_CTy>())) { - return partial_corrector<_ATy...>::correct(std::forward<_CTy>(functional)); + // 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 static auto box_continuable_trait(_CTy&& continuable) -> typename std::enable_if< @@ -472,7 +424,7 @@ namespace detail static_assert(std::is_rvalue_reference<_CTy&&>::value, "Given continuable must be passed as r-value!"); - // Trick C++11 lambda capture rules for non copyable but moveable continuables. + // Trick C++11 lambda capture rules for non move-only Continuables. // TODO Use the stack instead of heap variables. std::shared_ptr::type> shared_continuable = std::make_shared::type>(std::forward<_CTy>(continuable)); @@ -485,7 +437,6 @@ namespace detail } /// `box_continuable_trait`: Converts plain Continuables to continuable retuning functions. - /// TODO Move this into an acceptor helper class. template static auto correct_stage(_CTy&& functional) -> typename std::enable_if< @@ -500,7 +451,6 @@ namespace detail /// `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 static auto correct_stage(_CTy&& functional) -> typename std::enable_if< @@ -513,16 +463,50 @@ namespace detail return remove_void_trait(partialize_correct_trait(std::forward<_CTy>(functional))); } - /// Correct user given functionals through several stages into the form: + /// Accepts and corrects user given functionals through several stages into the form: /// Continuable<_CArgs...>(_FArgs) - /// TODO Move this into an acceptor helper class. template - static inline auto correct(_CTy&& functional) + static inline auto accept(_CTy&& functional) -> decltype(correct_stage(std::declval<_CTy>())) { return correct_stage(std::forward<_CTy>(functional)); } + }; + // Unwraps the corrected type of Continuables + template + struct continuable_unwrap + { + // Corrected user given functional + typedef decltype(continuable_acceptor<_ATy...>:: + accept(std::declval::type>())) accepted_t; + + typedef fu::return_type_of_t continuable_t; + + typedef fu::argument_type_of_t arguments_t; + + typedef typename continuable_t::CallbackFunction callback_t; + + typedef fu::argument_type_of_t callback_arguments_t; + }; + + /* + /// Position wrapper class to pass ints as type + template + struct partial_result + { + enum my_size : std::size_t + { + size = Position + }; + + typedef Tuple tuple; + }; + + /// Continuable processing detail implementation + template + struct functional_traits + { template struct multiple_result_maker; @@ -545,12 +529,12 @@ namespace detail Position + std::tuple_size< typename identity_to_tuple< - typename unary_chainer_t::callback_arguments_t + typename continuable_unwrap::callback_arguments_t >::type >::value, typename concat_identities< Args, - typename unary_chainer_t::callback_arguments_t + typename continuable_unwrap::callback_arguments_t >::type, typename concat_identities< Pack, @@ -558,7 +542,7 @@ namespace detail partial_result< Position, typename identity_to_tuple< - typename unary_chainer_t::callback_arguments_t + typename continuable_unwrap::callback_arguments_t >::type > > @@ -630,7 +614,7 @@ namespace detail } // Do nothing when trying to store empty packs... - inline static void store(std::tuple<_RTy...>& /*result*/) + inline static void store(std::tuple<_RTy...>&) { } @@ -779,6 +763,7 @@ namespace detail return make_result::create(std::forward<_CTy>(args)...); } }; + */ } #endif // _CONTINUABLE_H_