Correctly handle continuables with multiple results

This commit is contained in:
Denis Blank 2018-02-27 17:18:52 +01:00
parent 6e1350086e
commit 9c087e60d2
3 changed files with 28 additions and 20 deletions

View File

@ -206,14 +206,6 @@ constexpr auto tupelize(std::tuple<T...> arg) {
return std::move(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>) constexpr auto deduce_from_pack(traits::identity<void>)
-> hints::signature_hint_tag<>; -> hints::signature_hint_tag<>;
template <typename... T> 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>) constexpr auto deduce_from_pack(traits::identity<T>)
-> hints::signature_hint_tag<T>; -> hints::signature_hint_tag<T>;
template <typename Composition> // We must guard the mapped type against to be void since this represents an
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
// empty signature hint. // 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 } // namespace all
/// Finalizes the all logic of a given composition /// Finalizes the all logic of a given composition

View File

@ -56,12 +56,29 @@ namespace composition {
namespace remapping { namespace remapping {
// Guard object for representing void results // Guard object for representing void results
struct void_result_guard {}; 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 // 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 { auto operator()(void_result_guard) const noexcept {
return spread_this(); 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 { namespace detail {
@ -82,7 +99,8 @@ struct result_extractor_mapper {
static constexpr auto static constexpr auto
initialize(hints::signature_hint_tag<First, Second, Args...>) { initialize(hints::signature_hint_tag<First, Second, Args...>) {
// TODO Fix non default constructible values // 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 /// Remap a continuable to its corresponding result values

View File

@ -184,8 +184,8 @@ public:
template <typename T> template <typename T>
void operator()(async_traverse_complete_tag, T&& /*pack*/) { void operator()(async_traverse_complete_tag, T&& /*pack*/) {
// Remove void result guard tags // Remove void result guard tags
auto cleaned = all::flatten( auto cleaned =
map_pack(remapping::clean_void_results{}, std::move(data_.result))); map_pack(remapping::unpack_result_guards{}, std::move(data_.result));
// Call the final callback with the cleaned result // Call the final callback with the cleaned result
traits::unpack(std::move(cleaned), std::move(data_.callback)); traits::unpack(std::move(cleaned), std::move(data_.callback));