mirror of
https://github.com/Naios/continuable.git
synced 2025-12-06 16:56:44 +08:00
Correctly handle continuables with multiple results
This commit is contained in:
parent
6e1350086e
commit
9c087e60d2
@ -206,14 +206,6 @@ constexpr auto tupelize(std::tuple<T...> arg) {
|
||||
return std::move(arg);
|
||||
}
|
||||
|
||||
/// Lift the first tuple hierarchy inside the given tuple
|
||||
template <typename T>
|
||||
constexpr auto flatten(T&& tuple) {
|
||||
return traits::unpack(std::forward<T>(tuple), [](auto&&... args) {
|
||||
return std::tuple_cat(tupelize(std::forward<decltype(args)>(args))...);
|
||||
});
|
||||
}
|
||||
|
||||
constexpr auto deduce_from_pack(traits::identity<void>)
|
||||
-> hints::signature_hint_tag<>;
|
||||
template <typename... T>
|
||||
@ -223,15 +215,13 @@ template <typename T, std::enable_if_t<!is_tuple<T>::value>* = nullptr>
|
||||
constexpr auto deduce_from_pack(traits::identity<T>)
|
||||
-> hints::signature_hint_tag<T>;
|
||||
|
||||
template <typename Composition>
|
||||
constexpr auto deduce_hint(Composition&& /*composition*/) {
|
||||
using deduced_t =
|
||||
decltype(map_pack(all_hint_deducer{}, std::declval<Composition>()));
|
||||
|
||||
// We must guard deduced_t against to be void since this represents an
|
||||
// We must guard the mapped type against to be void since this represents an
|
||||
// empty signature hint.
|
||||
return decltype(deduce_from_pack(traits::identity<deduced_t>{})){};
|
||||
}
|
||||
template <typename Composition>
|
||||
constexpr auto deduce_hint(Composition && /*composition*/)
|
||||
-> decltype(deduce_from_pack(
|
||||
traits::identity<decltype(map_pack(all_hint_deducer{},
|
||||
std::declval<Composition>()))>{})){};
|
||||
} // namespace all
|
||||
|
||||
/// Finalizes the all logic of a given composition
|
||||
|
||||
@ -56,12 +56,29 @@ namespace composition {
|
||||
namespace remapping {
|
||||
// Guard object for representing void results
|
||||
struct void_result_guard {};
|
||||
// Guard object for representing multiple results
|
||||
template <typename... Args>
|
||||
struct multi_result_guard {
|
||||
std::tuple<Args...> result_;
|
||||
|
||||
multi_result_guard& operator=(std::tuple<Args...> result) {
|
||||
result_ = std::move(result);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
// Callable object that maps void_result_guard zo zero arguments
|
||||
struct clean_void_results {
|
||||
struct unpack_result_guards {
|
||||
auto operator()(void_result_guard) const noexcept {
|
||||
return spread_this();
|
||||
}
|
||||
template <typename... Args>
|
||||
auto operator()(multi_result_guard<Args...> guard) const noexcept {
|
||||
// Spread the result of the continuable into the current depth.
|
||||
return traits::unpack(std::move(guard.result_), [](auto&&... args) {
|
||||
return spread_this(std::forward<decltype(args)>(args)...);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
@ -82,7 +99,8 @@ struct result_extractor_mapper {
|
||||
static constexpr auto
|
||||
initialize(hints::signature_hint_tag<First, Second, Args...>) {
|
||||
// TODO Fix non default constructible values
|
||||
return std::make_tuple(First{}, Second{}, Args{}...);
|
||||
return multi_result_guard<First, Second, Args...>{
|
||||
std::make_tuple(First{}, Second{}, Args{}...)};
|
||||
}
|
||||
|
||||
/// Remap a continuable to its corresponding result values
|
||||
|
||||
@ -184,8 +184,8 @@ public:
|
||||
template <typename T>
|
||||
void operator()(async_traverse_complete_tag, T&& /*pack*/) {
|
||||
// Remove void result guard tags
|
||||
auto cleaned = all::flatten(
|
||||
map_pack(remapping::clean_void_results{}, std::move(data_.result)));
|
||||
auto cleaned =
|
||||
map_pack(remapping::unpack_result_guards{}, std::move(data_.result));
|
||||
|
||||
// Call the final callback with the cleaned result
|
||||
traits::unpack(std::move(cleaned), std::move(data_.callback));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user