From f81f0e649c26887f2ccdcc6c602f18e126e1d805 Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Mon, 19 Feb 2018 02:39:51 +0100 Subject: [PATCH] Initial work on creating the result object --- .../continuable/detail/container-category.hpp | 9 +- test/playground/CMakeLists.txt | 3 +- test/playground/comp.cpp | 158 ++++++++++++++++++ test/playground/test-playground.cpp | 63 ------- 4 files changed, 163 insertions(+), 70 deletions(-) create mode 100644 test/playground/comp.cpp diff --git a/include/continuable/detail/container-category.hpp b/include/continuable/detail/container-category.hpp index f98e2c4..ea19474 100644 --- a/include/continuable/detail/container-category.hpp +++ b/include/continuable/detail/container-category.hpp @@ -39,7 +39,6 @@ namespace cti { namespace detail { namespace traversal { -namespace detail { /// Deduces to a true type if the given parameter T /// has a begin() and end() method. // TODO Find out whether we should use std::begin and std::end instead, which @@ -59,18 +58,16 @@ template struct is_tuple_like::value)>> : std::true_type {}; -} // namespace detail - /// A tag for dispatching based on the tuple like /// or container properties of a type. template -struct container_category_tag {}; +struct container_category_tag + : std::integral_constant {}; /// Deduces to the container_category_tag of the given type T. template using container_category_of_t = - container_category_tag::value, - detail::is_tuple_like::value>; + container_category_tag::value, is_tuple_like::value>; } // namespace traversal } // namespace detail } // namespace cti diff --git a/test/playground/CMakeLists.txt b/test/playground/CMakeLists.txt index bfd1ca1..2d26959 100644 --- a/test/playground/CMakeLists.txt +++ b/test/playground/CMakeLists.txt @@ -25,7 +25,8 @@ set(LIB_SOURCES_DETAIL ${CMAKE_SOURCE_DIR}/include/continuable/detail/testing.hpp ${CMAKE_SOURCE_DIR}/include/continuable/detail/util.hpp) set(TEST - ${CMAKE_CURRENT_LIST_DIR}/test-playground.cpp) + ${CMAKE_CURRENT_LIST_DIR}/test-playground.cpp + ${CMAKE_CURRENT_LIST_DIR}/comp.cpp) add_executable(test-playground ${LIB_SOURCES} diff --git a/test/playground/comp.cpp b/test/playground/comp.cpp new file mode 100644 index 0000000..1763d4c --- /dev/null +++ b/test/playground/comp.cpp @@ -0,0 +1,158 @@ +/* + Copyright(c) 2015 - 2018 Denis Blank + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files(the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and / or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions : + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +**/ + +#include + +#include +#include +#include +#include + +// Devel +#include +#include + +namespace cti { +namespace detail { +/// This namespace provides utilities for performing compound +/// connections between deeply nested continuables and values. +/// +/// 0. We create the result pack from the provides values and +/// the async values if those are default constructible, +/// otherwise use a lazy initialization wrapper and unwrap +/// the whole pack when the composition is finished. +/// - value -> value +/// - single async value -> single value +/// - multiple async value -> tuple of async values. +/// +/// 1. +namespace remapping { +// Guard object for representing void results +struct void_result_guard {}; + +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<>) { + return void_result_guard{}; + } + /// Initialize a single value + template + static constexpr auto initialize(hints::signature_hint_tag) { + return First{}; + } + /// Initialize a multiple values as tuple + template + static constexpr auto initialize(hints::signature_hint_tag<>) { + // TODO Fix non default constructible values + return std::make_tuple(First{}, Second{}, Args{}...); + } + + /// Remap a continuable to its corresponding result values + /// A void result is mapped to a guard type, single values to the value + /// itself and multiple ones to a tuple of values. + template < + typename T, + std::enable_if_t>::value>* = nullptr> + auto operator()(T&& /*continuable*/) { + auto constexpr const hint = hints::hint_of(traits::identify{}); + return initialize(hint); + } +}; + +/// 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; + + template < + typename T, + std::enable_if_t>::value>* = nullptr> + auto operator()(T&& continuable) { + using type = indexed_continuable, Target>; + return type{std::forward(continuable), target}; + } + + template < + typename T, + std::enable_if_t>::value>* = nullptr> + auto operator()(T&& continuable) { + using type = indexed_continuable, Target>; + return type{std::forward(continuable), target}; + } +}; + +/// 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)...); +} +} // namespace remapping + +struct c {}; + +template +struct loc {}; + +struct runtime_insertion { + std::size_t begin, end; +}; + +template +struct future_result { + std::tuple result_; +}; +} // namespace detail +} // namespace cti + +using namespace cti::detail::remapping; + +int main(int, char**) { + + using namespace cti::detail; + + std::vector vc{1, 2, 3}; + + // std::tuple t; + // 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)); + + return 0; +} diff --git a/test/playground/test-playground.cpp b/test/playground/test-playground.cpp index 378c81d..28ef5a5 100644 --- a/test/playground/test-playground.cpp +++ b/test/playground/test-playground.cpp @@ -118,66 +118,3 @@ void some_requests() { // ... }); } - -namespace cti { -namespace detail { - -struct c {}; - -template -struct loc {}; - -struct runtime_insertion { - std::size_t begin, end; -}; - -template -struct future_result { - std::tuple result_; -}; - -template -struct static_insertion {}; - -template -struct indexer_frame { - std::tuple hierarchy_; - - template * = nullptr> - auto operator()(T&& continuable) { - } -}; - -struct result_extractor_mapper { - template >::value>* = nullptr> - auto operator()(T&& continuable) { - - } -}; - -// 0. We create the result pack from the provides values and -// the async values if those are default constructible, -// otherwise use a lazy initialization wrapper and unwrap -// the whole pack when the composition is finished. -// value -> value, single async value -> single value -// multiple async value -> tuple of async values. -// -// 1. - -} // namespace detail -} // namespace cti - -int main(int, char**) { - - using namespace cti::detail; - - std::vector vc{1, 2, 3}; - - // std::tuple t; - // std::tuple>, c, c> loc; - - cti::map_pack([](auto&& /*continuable*/) { return 0; }, vc); - - return 0; -}