From af9b89309e0ceba2f57f2910e7af2926ef862462 Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Thu, 2 Jul 2015 16:45:01 +0200 Subject: [PATCH] Worked on multiple function invocation --- include/Continuable.h | 48 +++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/include/Continuable.h b/include/Continuable.h index 9bfb829..6798714 100644 --- a/include/Continuable.h +++ b/include/Continuable.h @@ -488,13 +488,13 @@ namespace detail multiple_result_maker<0, fu::identity<>, fu::identity<>, Args...>; }; - template + template struct multiple_when_all_chainer_t_make_result; - template - struct multiple_when_all_chainer_t_make_result> + template + struct multiple_when_all_chainer_t_make_result, fu::identity<_RTy...>> { - typedef Continuable continuable_t; + typedef Continuable<_RTy...> continuable_t; typedef std::function return_t; @@ -505,19 +505,45 @@ namespace detail std::size_t count; - std::tuple result; + std::tuple<_RTy...> result; }; - template + typedef std::shared_ptr SharedResult; + + template + static void invoke(SharedResult storage, _CTy&& functional) + { + } + + // Invoke last + template + static void distribute_invoke(SharedResult storage, _CTy&& current) + { + invoke(storage, std::forward<_CTy>(current)); + } + + // Invoke and pass recursive to next + template + static void distribute_invoke(SharedResult storage, _CTy&& current, Rest&&... rest) + { + invoke(storage, std::forward<_CTy>(current)); + distribute_invoke(storage, std::forward(rest)...); + } + + /// Creates a faked function which invokes all sub continuables + template static return_t create(_CTy&&... functionals) { - return [=](_ATy&&... args) + return [=](_ATy&&... args) mutable { // Fake continuable which wraps all continuables together - return make_continuable([](Callback&& callback) + return make_continuable([=](Callback<_RTy...>&& callback) mutable { - std::shared_ptr result( - new ResultStorage(sizeof...(_CTy))); + SharedResult result(new ResultStorage(sizeof...(_CTy))); + + distribute_invoke(result, std::forward<_CTy>(functionals)...); + + // functional_traits<_ATy...>::correct(std::forward<_CTy>(functionals)) // auto shared = std::make_shared(ResultStorage()); @@ -542,7 +568,7 @@ namespace detail static std::size_t const size = result_maker::size; - typedef multiple_when_all_chainer_t_make_result make_result; + typedef multiple_when_all_chainer_t_make_result, arguments_t> make_result; // Creates one continuable from multiple ones static auto make_when_all(_CTy&&... args)