mirror of
https://github.com/Naios/continuable.git
synced 2025-12-06 16:56:44 +08:00
Fix the range_loop build
This commit is contained in:
parent
ac175b4e57
commit
a4da3e84ef
@ -55,9 +55,9 @@ namespace hints {
|
||||
///
|
||||
/// This is the overload taking an arbitrary amount of args
|
||||
template <typename... HintArgs>
|
||||
struct from_args : std::common_type<identity<HintArgs...>> {};
|
||||
struct from_args : std::common_type<signature_arg_t<HintArgs...>> {};
|
||||
template <>
|
||||
struct from_args<void> : std::common_type<identity<>> {};
|
||||
struct from_args<void> : std::common_type<signature_arg_t<>> {};
|
||||
} // namespace hints
|
||||
} // namespace detail
|
||||
} // namespace cti
|
||||
|
||||
@ -32,12 +32,31 @@
|
||||
#define CONTINUABLE_DETAIL_OPERATIONS_ASYNC_HPP_INCLUDED
|
||||
|
||||
#include <continuable/continuable-base.hpp>
|
||||
#include <continuable/detail/core/annotation.hpp>
|
||||
#include <continuable/detail/core/base.hpp>
|
||||
#include <continuable/detail/utility/identity.hpp>
|
||||
|
||||
namespace cti {
|
||||
namespace detail {
|
||||
namespace operations {
|
||||
template <typename... SignatureArgs, typename Callable, typename... Args>
|
||||
auto make_async(signature_arg_t<SignatureArgs...>, Callable&& callable,
|
||||
Args&&... args) {
|
||||
|
||||
auto continuation = [](auto&& promise) mutable { promise.set_value(); };
|
||||
|
||||
return base::attorney::create_from(std::move(continuation), //
|
||||
signature_arg_t<Args...>{},
|
||||
util::ownership{});
|
||||
}
|
||||
|
||||
template <typename Callable, typename... Args>
|
||||
auto async(Callable&& callable, Args&&... args) {
|
||||
using result_t = void;
|
||||
using invoker_t =
|
||||
decltype(base::decoration::invoker_of(identify<result_t>{}));
|
||||
return make_async(invoker_t::hint(), std::forward<Callable>(callable),
|
||||
std::forward<Args>(args)...);
|
||||
}
|
||||
} // namespace operations
|
||||
|
||||
|
||||
@ -154,17 +154,18 @@ auto loop(Callable&& callable, Args&&... args) {
|
||||
});
|
||||
}
|
||||
|
||||
template <typename Callable, typename Begin>
|
||||
auto make_range_looper(Callable&& callable, Begin&& begin) {
|
||||
template <typename Callable, typename Begin, typename End>
|
||||
auto make_range_looper(Callable&& callable, Begin&& begin, End&& end) {
|
||||
return [callable = std::forward<Callable>(callable),
|
||||
begin = std::forward<Begin>(begin)](auto&& end) mutable {
|
||||
begin = std::forward<Begin>(begin),
|
||||
end = std::forward<End>(end)]() mutable {
|
||||
return util::invoke(callable, begin)
|
||||
.then([&begin, // begin stays valid over the `then`.
|
||||
end = std::forward<decltype(end)>(end)]() mutable -> result<> {
|
||||
.then([&begin, &end]() mutable -> std::tuple<result<>> {
|
||||
// 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());
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@ -32,6 +32,7 @@
|
||||
#define CONTINUABLE_OPERATIONS_LOOP_HPP_INCLUDED
|
||||
|
||||
#include <utility>
|
||||
#include <continuable/continuable-result.hpp>
|
||||
#include <continuable/detail/operations/loop.hpp>
|
||||
|
||||
namespace cti {
|
||||
@ -45,9 +46,9 @@ auto loop(Callable&& callable, Args&&... args) {
|
||||
|
||||
template <typename Callable, typename Iterator>
|
||||
auto range_loop(Callable&& callable, Iterator begin, Iterator end) {
|
||||
auto looper = detail::operations::make_range_looper(
|
||||
std::forward<Callable>(callable), begin);
|
||||
return detail::operations::loop(std::move(looper), end);
|
||||
return detail::operations::loop( //
|
||||
detail::operations::make_range_looper(std::forward<Callable>(callable),
|
||||
begin, end));
|
||||
}
|
||||
/// \}
|
||||
} // namespace cti
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user