From a4da3e84ef1f4c372f58aa6779f488a13779bc08 Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Sun, 13 Jan 2019 17:05:22 +0100 Subject: [PATCH] Fix the range_loop build --- .../continuable/detail/core/annotation.hpp | 4 ++-- .../continuable/detail/operations/async.hpp | 19 +++++++++++++++++++ .../continuable/detail/operations/loop.hpp | 15 ++++++++------- include/continuable/operations/loop.hpp | 7 ++++--- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/include/continuable/detail/core/annotation.hpp b/include/continuable/detail/core/annotation.hpp index b1af9e5..37c9ecb 100644 --- a/include/continuable/detail/core/annotation.hpp +++ b/include/continuable/detail/core/annotation.hpp @@ -55,9 +55,9 @@ namespace hints { /// /// This is the overload taking an arbitrary amount of args template -struct from_args : std::common_type> {}; +struct from_args : std::common_type> {}; template <> -struct from_args : std::common_type> {}; +struct from_args : std::common_type> {}; } // namespace hints } // namespace detail } // namespace cti diff --git a/include/continuable/detail/operations/async.hpp b/include/continuable/detail/operations/async.hpp index 71e1fd1..e9cccd9 100644 --- a/include/continuable/detail/operations/async.hpp +++ b/include/continuable/detail/operations/async.hpp @@ -32,12 +32,31 @@ #define CONTINUABLE_DETAIL_OPERATIONS_ASYNC_HPP_INCLUDED #include +#include +#include +#include namespace cti { namespace detail { namespace operations { +template +auto make_async(signature_arg_t, Callable&& callable, + Args&&... args) { + + auto continuation = [](auto&& promise) mutable { promise.set_value(); }; + + return base::attorney::create_from(std::move(continuation), // + signature_arg_t{}, + util::ownership{}); +} + template auto async(Callable&& callable, Args&&... args) { + using result_t = void; + using invoker_t = + decltype(base::decoration::invoker_of(identify{})); + return make_async(invoker_t::hint(), std::forward(callable), + std::forward(args)...); } } // namespace operations diff --git a/include/continuable/detail/operations/loop.hpp b/include/continuable/detail/operations/loop.hpp index 0099736..e663b87 100644 --- a/include/continuable/detail/operations/loop.hpp +++ b/include/continuable/detail/operations/loop.hpp @@ -154,17 +154,18 @@ auto loop(Callable&& callable, Args&&... args) { }); } -template -auto make_range_looper(Callable&& callable, Begin&& begin) { +template +auto make_range_looper(Callable&& callable, Begin&& begin, End&& end) { return [callable = std::forward(callable), - begin = std::forward(begin)](auto&& end) mutable { + begin = std::forward(begin), + end = std::forward(end)]() mutable { return util::invoke(callable, begin) - .then([&begin, // begin stays valid over the `then`. - end = std::forward(end)]() mutable -> result<> { + .then([&begin, &end]() mutable -> std::tuple> { + // begin and end stays valid over the `then` here if (++begin != end) { - return empty_result{}; + return std::make_tuple(result<>(empty_result{})); } else { - return make_result(); + return std::make_tuple(make_result()); } }); }; diff --git a/include/continuable/operations/loop.hpp b/include/continuable/operations/loop.hpp index 76a6a61..773e8df 100644 --- a/include/continuable/operations/loop.hpp +++ b/include/continuable/operations/loop.hpp @@ -32,6 +32,7 @@ #define CONTINUABLE_OPERATIONS_LOOP_HPP_INCLUDED #include +#include #include namespace cti { @@ -45,9 +46,9 @@ auto loop(Callable&& callable, Args&&... args) { template auto range_loop(Callable&& callable, Iterator begin, Iterator end) { - auto looper = detail::operations::make_range_looper( - std::forward(callable), begin); - return detail::operations::loop(std::move(looper), end); + return detail::operations::loop( // + detail::operations::make_range_looper(std::forward(callable), + begin, end)); } /// \} } // namespace cti