Add result caching

This commit is contained in:
Naios 2015-07-02 20:34:05 +02:00
parent 9ddd746367
commit 92e16630c1

View File

@ -515,6 +515,23 @@ namespace detail
template <std::size_t... Sequence, std::size_t Offset> template <std::size_t... Sequence, std::size_t Offset>
struct result_store_sequencer<fu::sequence<Sequence...>, Offset> struct result_store_sequencer<fu::sequence<Sequence...>, Offset>
{ {
template<std::size_t Position, typename Tuple, typename Current>
inline static void partial_set(Tuple& result, Current&& current)
{
// Store the callback result in the tuple
std::get<Position>(result) = std::forward<Current>(current);
}
template<std::size_t Position, typename Tuple, typename Current, typename... Rest>
inline static void partial_set(Tuple& result, Current&& current, Rest&&... rest)
{
// Set the result...
partial_set<Position, Tuple, Current>(result, std::forward<Current>(current));
// ...and continue with the next parameter.
partial_set<Position + 1, Tuple, Rest...>(result, std::forward<Rest>(rest)...);
}
// Do nothing when trying to store empty packs... // Do nothing when trying to store empty packs...
inline static void store(std::tuple<_RTy...>& result) inline static void store(std::tuple<_RTy...>& result)
{ {
@ -524,6 +541,7 @@ namespace detail
template<typename... Args> template<typename... Args>
inline static void store(std::tuple<_RTy...>& result, Args&&... args) inline static void store(std::tuple<_RTy...>& result, Args&&... args)
{ {
partial_set<Offset, std::tuple<_RTy...>, Args...>(result, std::forward<Args>(args)...);
} }
}; };
@ -601,12 +619,10 @@ namespace detail
{ {
// Invoke the continuable from the result storage // Invoke the continuable from the result storage
invoker_at<Position>::invoke( invoker_at<Position>::invoke(
storage, storage,
fu::invoke_from_tuple( fu::invoke_from_tuple(
traits_t::correct(std::forward<_CTy>(current)), traits_t::correct(std::forward<_CTy>(current)),
std::forward<Arguments>(args))); std::forward<Arguments>(args)));
// std::cout << "invoking: " << Position << " " << typeid(ret).name() << std::endl;
} }
/// Invoke and pass recursive to itself /// Invoke and pass recursive to itself
@ -631,8 +647,7 @@ namespace detail
distributor<_PTy...>::invoke( distributor<_PTy...>::invoke(
result, result,
std::forward<Arguments>(arguments), std::forward<Arguments>(arguments),
std::get<Sequence>(std::forward<TupleFunctional>(functional))... std::get<Sequence>(std::forward<TupleFunctional>(functional))...);
);
} }
}; };
@ -651,8 +666,7 @@ namespace detail
// TODO Use the stack instead of heap variables. // TODO Use the stack instead of heap variables.
auto shared_args = auto shared_args =
std::make_shared<std::tuple<_ATy...>>( std::make_shared<std::tuple<_ATy...>>(
std::make_tuple(std::forward<_ATy>(args)...) std::make_tuple(std::forward<_ATy>(args)...));
);
// Fake continuable which wraps all continuables together // Fake continuable which wraps all continuables together
return make_continuable([=](Callback<_RTy...>&& callback) mutable return make_continuable([=](Callback<_RTy...>&& callback) mutable