From 45b46552e4bfcd11d06da3f76ad000e47c09a20b Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Thu, 2 Jul 2015 20:15:50 +0200 Subject: [PATCH] more work --- include/Continuable.h | 54 ++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/include/Continuable.h b/include/Continuable.h index f84990a..4f4fa47 100644 --- a/include/Continuable.h +++ b/include/Continuable.h @@ -66,6 +66,9 @@ namespace detail template class multiple_result_storage_t; + template + struct multiple_result_storage_invoker_t; + /// Functional traits forward declaration. template struct functional_traits; @@ -81,8 +84,8 @@ class Continuable template friend class Continuable; - template - friend class detail::multiple_result_storage_t; + template + friend struct detail::multiple_result_storage_invoker_t; public: typedef Callback<_ATy...> CallbackFunction; @@ -506,13 +509,13 @@ namespace detail std::mutex lock; - template + template struct result_store_sequencer; template - struct result_store_sequencer < fu::sequence, Offset > + struct result_store_sequencer, Offset> { - // Do nothing + // Do nothing when trying to store empty packs... inline static void store(std::tuple<_RTy...>& result) { } @@ -528,17 +531,19 @@ namespace detail multiple_result_storage_t(std::size_t partitions, Callback<_RTy...> callback_) : partitions_left(partitions), callback(callback_) { } - template - void store_result(Args&&... args) + template + void store(Args&&... args) { result_store_sequencer< fu::sequence_of_t, - Position + Offset >::store(result, std::forward(args)...); // TODO Improve the lock here std::lock_guard guard(lock); { + std::cout << "storing..." << std::endl; + // If all partitions have completed invoke the final callback. if (--partitions_left == 0) { @@ -548,6 +553,21 @@ namespace detail } }; + template + struct multiple_result_storage_invoker_t, fu::identity<_RTy...>, fu::identity<_PTy...>> + { + template + static void invoke( + std::shared_ptr, fu::identity<_RTy...>, fu::identity<_PTy...>>> storage, + Continuable&& continuable) + { + continuable.invoke([storage](Args&&... args) + { + storage->store(std::forward(args)...); + }); + } + }; + template struct multiple_when_all_chainer_t_make_result; @@ -562,6 +582,9 @@ namespace detail typedef multiple_result_storage_t, fu::identity<_RTy...>, fu::identity<_PTy...>> ResultStorage; + template + using invoker_at = multiple_result_storage_invoker_t, fu::identity<_RTy...>, fu::identity<_PTy...>>; + typedef std::shared_ptr shared_result_t; typedef std::tuple<_ATy...> shared_args_t; @@ -576,15 +599,14 @@ namespace detail template inline static void invoke(shared_result_t storage, Arguments&& args, _CTy&& current) { - auto ret = - fu::invoke_from_tuple( - traits_t::correct(std::forward<_CTy>(current)), - std::forward(args) - ); + // Invoke the continuable from the result storage + invoker_at::invoke( + storage, + fu::invoke_from_tuple( + traits_t::correct(std::forward<_CTy>(current)), + std::forward(args))); - // TODO invalidate tuple - - std::cout << "invoking: " << Position << " " << typeid(ret).name() << std::endl; + // std::cout << "invoking: " << Position << " " << typeid(ret).name() << std::endl; } /// Invoke and pass recursive to itself