diff --git a/include/continuable/detail/container-category.hpp b/include/continuable/detail/container-category.hpp index ea19474..7bdbdee 100644 --- a/include/continuable/detail/container-category.hpp +++ b/include/continuable/detail/container-category.hpp @@ -60,6 +60,8 @@ struct is_tuple_like::value)>> /// A tag for dispatching based on the tuple like /// or container properties of a type. +/// +/// This type deduces to a true_type if it has any category. template struct container_category_tag : std::integral_constant {}; diff --git a/include/continuable/detail/traverse.hpp b/include/continuable/detail/traverse.hpp index 4e46191..d242131 100644 --- a/include/continuable/detail/traverse.hpp +++ b/include/continuable/detail/traverse.hpp @@ -735,7 +735,7 @@ class mapping_helper : protected mapping_strategy_base { -> decltype(std::declval().invoke_mapper( std::forward(element))) { // T could be any non container or non tuple like type here, - // take int or hpx::future as an example. + // take int or std::future as an example. return invoke_mapper(std::forward(element)); } diff --git a/test/playground/comp.cpp b/test/playground/comp.cpp index 1763d4c..c381eb1 100644 --- a/test/playground/comp.cpp +++ b/test/playground/comp.cpp @@ -49,11 +49,20 @@ namespace remapping { // Guard object for representing void results struct void_result_guard {}; +/// Contains an continuable together with a location where the +/// result shall be stored. +template +struct indexed_continuable { + Continuable continuable; + Target* target; +}; + +namespace detail { struct result_extractor_mapper { /// Create slots for a void result which is removed later. /// This is required due to the fact that each continuable has exactly /// one matching valuen inside the result tuple. - static constexpr auto initialize(hints::signature_hint_tag<>) { + static constexpr auto initialize(hints::signature_hint_tag<>) noexcept { return void_result_guard{}; } /// Initialize a single value @@ -80,47 +89,79 @@ struct result_extractor_mapper { } }; -/// Returns the result pack of the given deeply nested pack. -/// This invalidates all non-continuable values contained inside the pack. -template -constexpr auto create_result_pack(Args&&... args) { - return cti::map_pack(result_extractor_mapper{}, std::forward(args)...); -} - -/// Contains an continuable together with a location where the -/// result shall be stored. -template -struct indexed_continuable { - Continuable continuable; - Target* target; -}; - -template -struct result_indexer { - Target* target; - +/// Maps a deeply nested pack of continuables to +struct result_indexer_mapper { + /// Index a given continuable together with its target location template < typename T, std::enable_if_t>::value>* = nullptr> auto operator()(T&& continuable) { - using type = indexed_continuable, Target>; - return type{std::forward(continuable), target}; + auto constexpr const hint = hints::hint_of(traits::identify{}); + + using target = decltype(result_extractor_mapper::initialize(hint)); + + using type = indexed_continuable, target>; + return type{std::forward(continuable), nullptr}; } - template < + /// Remove all other non container values from this pack + /*template < typename T, - std::enable_if_t>::value>* = nullptr> - auto operator()(T&& continuable) { - using type = indexed_continuable, Target>; - return type{std::forward(continuable), target}; - } + typename Category = traversal::container_category_of_t>, + std::enable_if_t* = nullptr> + auto operator()(T&&) { + return spread_this(); + }*/ }; +} // namespace detail -/// Returns the index pack of the given deeply nested pack -template -constexpr auto index_result_pack(Target* target, Args&&... args) { - return cti::map_pack(result_extractor_mapper{}, std::forward(args)...); +/// Returns the result pack of the given deeply nested pack. +/// This invalidates all non-continuable values contained inside the pack. +/// +/// This consumes all non continuables inside the pack. +template +constexpr auto create_result_pack(Args&&... args) { + return cti::map_pack(detail::result_extractor_mapper{}, + std::forward(args)...); } + +/// Returns the result pack of the given deeply nested pack. +/// This invalidates all non-continuable values contained inside the pack. +/// +/// This consumes all continuables inside the pack. +template +constexpr auto create_index_pack(Args&&... args) { + return cti::map_pack(detail::result_indexer_mapper{}, + std::forward(args)...); +} + +/// Sets the target pointers of indexed_continuable's inside the index pack +/// to point to their given counterparts inside the given target. +template +constexpr auto relocate_index_pack(Index* index, Target* target) { + /*return cti::map_pack(detail::result_indexer_mapper{}, + std::forward(args)...);*/ +} + +/* +template +auto remape_container(traversal::container_category_tag, + T&& container) { +} + +template +auto remape_container(traversal::container_category_tag, + T&& container) { +} + +template < + typename T, + typename Category = traversal::container_category_of_t>, + std::enable_if_t* = nullptr> +auto operator()(T&& container) { + return remape_container(std::forward(container)); +} + */ } // namespace remapping struct c {}; @@ -151,8 +192,11 @@ int main(int, char**) { // std::tuple>, c, c> loc; auto p = - create_result_pack(0, 4, cti::make_ready_continuable(0), - std::make_tuple(1, 2), cti::make_ready_continuable(0)); + std::make_tuple(0, 4, cti::make_ready_continuable(0), + std::make_tuple(1, 2), cti::make_ready_continuable(0)); + + auto r = create_result_pack(std::move(p)); + auto i = create_index_pack(std::move(p)); return 0; }