From e82a2be2677f93b72c65ad070b354433a978c40e Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Thu, 2 Jul 2015 20:34:05 +0200 Subject: [PATCH] Add result caching --- include/Continuable.h | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/include/Continuable.h b/include/Continuable.h index 4f4fa47..1ced299 100644 --- a/include/Continuable.h +++ b/include/Continuable.h @@ -515,6 +515,23 @@ namespace detail template struct result_store_sequencer, Offset> { + template + inline static void partial_set(Tuple& result, Current&& current) + { + // Store the callback result in the tuple + std::get(result) = std::forward(current); + } + + template + inline static void partial_set(Tuple& result, Current&& current, Rest&&... rest) + { + // Set the result... + partial_set(result, std::forward(current)); + + // ...and continue with the next parameter. + partial_set(result, std::forward(rest)...); + } + // Do nothing when trying to store empty packs... inline static void store(std::tuple<_RTy...>& result) { @@ -524,6 +541,7 @@ namespace detail template inline static void store(std::tuple<_RTy...>& result, Args&&... args) { + partial_set, Args...>(result, std::forward(args)...); } }; @@ -601,12 +619,10 @@ namespace detail { // 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))); - - // std::cout << "invoking: " << Position << " " << typeid(ret).name() << std::endl; + storage, + fu::invoke_from_tuple( + traits_t::correct(std::forward<_CTy>(current)), + std::forward(args))); } /// Invoke and pass recursive to itself @@ -631,8 +647,7 @@ namespace detail distributor<_PTy...>::invoke( result, std::forward(arguments), - std::get(std::forward(functional))... - ); + std::get(std::forward(functional))...); } }; @@ -651,8 +666,7 @@ namespace detail // TODO Use the stack instead of heap variables. auto shared_args = std::make_shared>( - std::make_tuple(std::forward<_ATy>(args)...) - ); + std::make_tuple(std::forward<_ATy>(args)...)); // Fake continuable which wraps all continuables together return make_continuable([=](Callback<_RTy...>&& callback) mutable