Fix a remapping failure when nested tuples are involved

This commit is contained in:
Denis Blank 2018-02-27 17:18:52 +01:00
parent 2cbac4da98
commit 17f454ceb6
3 changed files with 24 additions and 14 deletions

View File

@ -162,11 +162,11 @@ struct result_relocator_mapper {
void traverse_tuple_like(std::integer_sequence<std::size_t, I...>, void traverse_tuple_like(std::integer_sequence<std::size_t, I...>,
Index* index, Result* result) { Index* index, Result* result) {
(void)std::initializer_list<int>{( (void)std::initializer_list<int>{
(void)traverse( ((void)traverse(traversal::container_category_of_t<
traversal::container_category_of_t<decltype(std::get<I>(*index))>{}, std::decay_t<decltype(std::get<I>(*index))>>{},
&std::get<I>(*index), &std::get<I>(*result)), &std::get<I>(*index), &std::get<I>(*result)),
0)...}; 0)...};
} }
/// Traverse tuple like container /// Traverse tuple like container
@ -197,7 +197,7 @@ template <typename Relocator, typename Index, typename Target>
constexpr void relocate_index_pack(Relocator&& relocator, Index* index, constexpr void relocate_index_pack(Relocator&& relocator, Index* index,
Target* target) { Target* target) {
constexpr traversal::container_category_of_t<Index> const tag; constexpr traversal::container_category_of_t<std::decay_t<Index>> const tag;
detail::result_relocator_mapper<std::decay_t<Relocator>> mapper{ detail::result_relocator_mapper<std::decay_t<Relocator>> mapper{
std::forward<Relocator>(relocator)}; std::forward<Relocator>(relocator)};

View File

@ -31,14 +31,15 @@
#ifndef CONTINUABLE_DETAIL_COMPOSITION_SEQ_HPP_INCLUDED #ifndef CONTINUABLE_DETAIL_COMPOSITION_SEQ_HPP_INCLUDED
#define CONTINUABLE_DETAIL_COMPOSITION_SEQ_HPP_INCLUDED #define CONTINUABLE_DETAIL_COMPOSITION_SEQ_HPP_INCLUDED
#include <cassert>
#include <memory> #include <memory>
#include <tuple> #include <tuple>
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
#include <continuable/continuable-promise-base.hpp>
#include <continuable/continuable-traverse-async.hpp> #include <continuable/continuable-traverse-async.hpp>
#include <continuable/detail/base.hpp> #include <continuable/detail/base.hpp>
#include <continuable/detail/composition_all.hpp>
#include <continuable/detail/composition_remapping.hpp> #include <continuable/detail/composition_remapping.hpp>
#include <continuable/detail/traits.hpp> #include <continuable/detail/traits.hpp>
@ -87,14 +88,14 @@ struct result_indexer_mapper {
template < template <
typename T, typename T,
std::enable_if_t<base::is_continuable<std::decay_t<T>>::value>* = nullptr> std::enable_if_t<base::is_continuable<std::decay_t<T>>::value>* = nullptr>
auto operator()(T& continuable) { auto operator()(T&& continuable) {
auto constexpr const hint = hints::hint_of(traits::identify<T>{}); auto constexpr const hint = hints::hint_of(traits::identify<T>{});
using target = using target =
decltype(remapping::detail::result_extractor_mapper::initialize(hint)); decltype(remapping::detail::result_extractor_mapper::initialize(hint));
using type = indexed_continuable<std::decay_t<T>, target>; using type = indexed_continuable<std::decay_t<T>, target>;
return type{std::move(continuable), nullptr}; return type{std::forward<T>(continuable), nullptr};
} }
}; };
@ -167,6 +168,9 @@ public:
template <typename Index, typename N> template <typename Index, typename N>
void operator()(async_traverse_detach_tag, Index&& index, N&& next) { 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) std::move(index.continuable)
.then([ target = index.target, .then([ target = index.target,
@ -198,7 +202,9 @@ template <>
struct composition_finalizer<composition_strategy_seq_tag> { struct composition_finalizer<composition_strategy_seq_tag> {
template <typename Composition> template <typename Composition>
static constexpr auto hint() { static constexpr auto hint() {
return decltype(all::deduce_hint(std::declval<Composition>())){}; // The result is the same as in the all composition
using all_finalizer = composition_finalizer<composition_strategy_all_tag>;
return all_finalizer::hint<Composition>();
} }
/// Finalizes the all logic of a given composition /// Finalizes the all logic of a given composition

View File

@ -124,10 +124,14 @@ void old() {
int main(int, char**) { int main(int, char**) {
using namespace cti::detail; using namespace cti::detail;
apply_composition(composition::composition_strategy_seq_tag{}, apply_composition(
cti::make_ready_continuable(0, 1), 2) composition::composition_strategy_seq_tag{},
.then([](int a0, int a1, int a2) { cti::make_ready_continuable(0, 1), 2,
std::vector<cti::continuable<int>>{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);
}); });
} }