From 331d642e5de6660aba174ae45642a795f2fd760f Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Mon, 26 Feb 2018 18:33:26 +0100 Subject: [PATCH] Fix a build error in the result indexing --- examples/example-asio/example-asio.cpp | 25 ++++--- include/continuable/continuable-promisify.hpp | 3 + test/playground/comp.cpp | 66 +++---------------- 3 files changed, 29 insertions(+), 65 deletions(-) diff --git a/examples/example-asio/example-asio.cpp b/examples/example-asio/example-asio.cpp index 3564b0c..d559731 100644 --- a/examples/example-asio/example-asio.cpp +++ b/examples/example-asio/example-asio.cpp @@ -40,15 +40,16 @@ using namespace std::chrono_literals; -struct functional_io_service : asio::io_service { +struct functional_io_service { + asio::io_context service_; asio::ip::udp::resolver resolver_; - functional_io_service() : resolver_(*this) { + functional_io_service() : resolver_(service_) { } - auto post() const noexcept { - return [this](auto&& work) { - asio::io_service::post(std::forward(work)); + auto trough_post() noexcept { + return [&](auto&& work) mutable { + service_.post(std::forward(work)); }; } @@ -66,6 +67,10 @@ struct functional_io_service : asio::io_service { }, std::move(host), std::move(service)); } + + void run() { + service_.run(); + } }; int main(int, char**) { @@ -74,10 +79,12 @@ int main(int, char**) { functional_io_service service; service.async_resolve("127.0.0.1", "daytime") - .then([](udp::resolver::iterator iterator) { - // ... - return *iterator; - }) + .then( + [](udp::resolver::iterator iterator) { + // ... + return *iterator; + }, + service.trough_post()) .then([](udp::endpoint /*endpoint*/) { // auto socket = std::make_shared(service); // socket->async_send_to() diff --git a/include/continuable/continuable-promisify.hpp b/include/continuable/continuable-promisify.hpp index 050e238..9840df0 100644 --- a/include/continuable/continuable-promisify.hpp +++ b/include/continuable/continuable-promisify.hpp @@ -45,6 +45,8 @@ namespace cti { /// /// \tparam Result The result of the converted continuable, this should align /// with the arguments that are passed to the callback. +/// +/// \since 3.0.0 template class promisify { using helper = detail::convert::promisify_helper; @@ -72,6 +74,7 @@ public: /// - If exceptions are disabled the error type is copnverted to an /// `std::error_conditon` and passed down to the error handler. /// + /// \since 3.0.0 template static auto from_asio(Callable&& callable, Args&&... args) { return helper::template from( diff --git a/test/playground/comp.cpp b/test/playground/comp.cpp index da74205..c7cca28 100644 --- a/test/playground/comp.cpp +++ b/test/playground/comp.cpp @@ -131,12 +131,7 @@ struct result_relocator_mapper { void traverse(traversal::container_category_tag, Index* index, Result* result) { - auto id = traits::identity>{}; - auto i = is_indexed_continuable>::value; - auto res = traits::is_invocable{}; - evaluator(index, result); - traverse_one(traits::is_invocable{}, index, result); } @@ -216,48 +211,22 @@ constexpr void relocate_index_pack(Relocator&& relocator, Index* index, mapper.traverse(tag, index, target); } -/* -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)); -} - */ +struct index_relocator { + template ::value>* = nullptr> + auto operator()(Index* index, Target* target) const noexcept { + // Assign the address of the target to the indexed continuable + index->target = target; + } +}; } // 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; + using namespace remapping; std::vector vc{1, 2, 3}; @@ -269,22 +238,7 @@ int main(int, char**) { auto r = create_result_pack(std::move(p)); auto i = create_index_pack(std::move(p)); - - /*relocate_index_pack( - [](auto index, auto result) - -> std::enable_if_t>>::value> { - - // Assign the address of the target to the indexed continuable - index->target = result; - - return; - }, - &i, &r);*/ - - auto t = [](auto&&...) {}; - - promisify::from(t, ""); + relocate_index_pack(index_relocator{}, &i, &r); return 0; }