From 17f454ceb68840f11efe92f9f2bebe227c41cd8f Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Tue, 27 Feb 2018 17:18:52 +0100 Subject: [PATCH] Fix a remapping failure when nested tuples are involved --- .../continuable/detail/composition_remapping.hpp | 12 ++++++------ include/continuable/detail/composition_seq.hpp | 14 ++++++++++---- test/playground/test-playground.cpp | 12 ++++++++---- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/include/continuable/detail/composition_remapping.hpp b/include/continuable/detail/composition_remapping.hpp index d664528..345c1a8 100644 --- a/include/continuable/detail/composition_remapping.hpp +++ b/include/continuable/detail/composition_remapping.hpp @@ -162,11 +162,11 @@ struct result_relocator_mapper { void traverse_tuple_like(std::integer_sequence, Index* index, Result* result) { - (void)std::initializer_list{( - (void)traverse( - traversal::container_category_of_t(*index))>{}, - &std::get(*index), &std::get(*result)), - 0)...}; + (void)std::initializer_list{ + ((void)traverse(traversal::container_category_of_t< + std::decay_t(*index))>>{}, + &std::get(*index), &std::get(*result)), + 0)...}; } /// Traverse tuple like container @@ -197,7 +197,7 @@ template constexpr void relocate_index_pack(Relocator&& relocator, Index* index, Target* target) { - constexpr traversal::container_category_of_t const tag; + constexpr traversal::container_category_of_t> const tag; detail::result_relocator_mapper> mapper{ std::forward(relocator)}; diff --git a/include/continuable/detail/composition_seq.hpp b/include/continuable/detail/composition_seq.hpp index 4bc66ae..d1f6d8c 100644 --- a/include/continuable/detail/composition_seq.hpp +++ b/include/continuable/detail/composition_seq.hpp @@ -31,14 +31,15 @@ #ifndef CONTINUABLE_DETAIL_COMPOSITION_SEQ_HPP_INCLUDED #define CONTINUABLE_DETAIL_COMPOSITION_SEQ_HPP_INCLUDED +#include #include #include #include #include -#include #include #include +#include #include #include @@ -87,14 +88,14 @@ struct result_indexer_mapper { template < typename T, std::enable_if_t>::value>* = nullptr> - auto operator()(T& continuable) { + auto operator()(T&& continuable) { auto constexpr const hint = hints::hint_of(traits::identify{}); using target = decltype(remapping::detail::result_extractor_mapper::initialize(hint)); using type = indexed_continuable, target>; - return type{std::move(continuable), nullptr}; + return type{std::forward(continuable), nullptr}; } }; @@ -167,6 +168,9 @@ public: template void operator()(async_traverse_detach_tag, Index&& index, N&& next) { + assert(index.target && "The target should be non null here!" + "Probably this is caused through a bug in " + "result_relocator_mapper!"); std::move(index.continuable) .then([ target = index.target, @@ -198,7 +202,9 @@ template <> struct composition_finalizer { template static constexpr auto hint() { - return decltype(all::deduce_hint(std::declval())){}; + // The result is the same as in the all composition + using all_finalizer = composition_finalizer; + return all_finalizer::hint(); } /// Finalizes the all logic of a given composition diff --git a/test/playground/test-playground.cpp b/test/playground/test-playground.cpp index 461c865..fdc7b26 100644 --- a/test/playground/test-playground.cpp +++ b/test/playground/test-playground.cpp @@ -124,10 +124,14 @@ void old() { int main(int, char**) { using namespace cti::detail; - apply_composition(composition::composition_strategy_seq_tag{}, - cti::make_ready_continuable(0, 1), 2) - .then([](int a0, int a1, int a2) { + apply_composition( + composition::composition_strategy_seq_tag{}, + cti::make_ready_continuable(0, 1), 2, + std::vector>{cti::make_ready_continuable(8), + cti::make_ready_continuable(9)}, + std::make_tuple(std::make_tuple(cti::make_ready_continuable(7)))) + .then([](int a0, int a1, int a2, auto o1, auto o2) { // ... - util::unused(a0, a1, a2); + util::unused(a0, a1, a2, o1, o2); }); }