From cd2ea28a53e1f4f9f77ff962207b95358c2074db Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Fri, 13 Dec 2024 11:15:21 +0800 Subject: [PATCH] removed leaf support. Closes #213 --- .drone.star | 1 - CMakeLists.txt | 1 - build.jam | 1 - doc/index.adoc | 1 - doc/reference/leaf.adoc | 26 ----- include/boost/cobalt.hpp | 1 - include/boost/cobalt/detail/leaf.hpp | 85 --------------- include/boost/cobalt/leaf.hpp | 51 --------- test/CMakeLists.txt | 2 +- test/leaf.cpp | 149 --------------------------- 10 files changed, 1 insertion(+), 317 deletions(-) delete mode 100644 doc/reference/leaf.adoc delete mode 100644 include/boost/cobalt/detail/leaf.hpp delete mode 100644 include/boost/cobalt/leaf.hpp delete mode 100644 test/leaf.cpp diff --git a/.drone.star b/.drone.star index 9537552c..15350860 100644 --- a/.drone.star +++ b/.drone.star @@ -30,7 +30,6 @@ deps = [ 'libs/intrusive', 'libs/io', 'libs/iterator', - 'libs/leaf', 'libs/mpl', 'libs/move', 'libs/mp11', diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a51d528..3029ac86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,6 @@ if (NOT BOOST_COBALT_IS_ROOT) Boost::config Boost::core Boost::intrusive - Boost::leaf Boost::mp11 Boost::preprocessor Boost::smart_ptr diff --git a/build.jam b/build.jam index 382acdc5..59966bf0 100644 --- a/build.jam +++ b/build.jam @@ -17,7 +17,6 @@ constant boost_dependencies : /boost/context//boost_context /boost/core//boost_core /boost/intrusive//boost_intrusive - /boost/leaf//boost_leaf /boost/mp11//boost_mp11 /boost/preprocessor//boost_preprocessor /boost/smart_ptr//boost_smart_ptr diff --git a/doc/index.adoc b/doc/index.adoc index 56600034..22f21e90 100644 --- a/doc/index.adoc +++ b/doc/index.adoc @@ -77,7 +77,6 @@ include::reference/result.adoc[] include::reference/async_for.adoc[] include::reference/error.adoc[] include::reference/config.adoc[] -include::reference/leaf.adoc[] include::reference/experimental/context.adoc[] diff --git a/doc/reference/leaf.adoc b/doc/reference/leaf.adoc deleted file mode 100644 index aa9a4a09..00000000 --- a/doc/reference/leaf.adoc +++ /dev/null @@ -1,26 +0,0 @@ -[#leaf] -== cobalt/leaf.hpp - -Async provides integration with boost.leaf. -It provides functions similar to leaf that take an <> -instead of a function object and return an <>. - - -[source,cpp] ----- -template -auto try_catch(TryAwaitable && try_coro, H && ... h ); - -template -auto try_handle_all(TryAwaitable && try_coro, H && ... h ); - -template -auto try_handle_some(TryAwaitable && try_coro, H && ... h ); ----- - -See the leaf documentation for details. - -- https://www.boost.org/doc/libs/master/libs/leaf/doc/html/index.html#try_catch[try_catch] -- https://www.boost.org/doc/libs/master/libs/leaf/doc/html/index.html#try_handle_all[try_handle_all] -- https://www.boost.org/doc/libs/master/libs/leaf/doc/html/index.html#try_handle_some[try_handle_some] - diff --git a/include/boost/cobalt.hpp b/include/boost/cobalt.hpp index c3f01aaa..98cb86f1 100644 --- a/include/boost/cobalt.hpp +++ b/include/boost/cobalt.hpp @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include diff --git a/include/boost/cobalt/detail/leaf.hpp b/include/boost/cobalt/detail/leaf.hpp deleted file mode 100644 index 0fe4e511..00000000 --- a/include/boost/cobalt/detail/leaf.hpp +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (c) 2023 Klemens D. Morgenstern -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#ifndef BOOST_COBALT_DETAIL_LEAF_HPP -#define BOOST_COBALT_DETAIL_LEAF_HPP - -#include -#include -#include - -namespace boost::cobalt::detail -{ - -template -struct [[nodiscard]] try_catch_awaitable -{ - Awaitable aw; - std::tuple handler; - - bool await_ready() {return aw.await_ready(); } - template - auto await_suspend(std::coroutine_handle h) {return aw.await_suspend(h);} - - auto await_resume() - { - return std::apply( - [this](auto && ... h) - { - return leaf::try_catch( - [this]{return std::move(aw).await_resume();}, - std::move(h)...); - }, std::move(handler)); - } -}; - -template -struct [[nodiscard]] try_handle_all_awaitable -{ - Awaitable aw; - std::tuple handler; - - bool await_ready() {return aw.await_ready(); } - template - auto await_suspend(std::coroutine_handle h) {return aw.await_suspend(h);} - - auto await_resume() - { - return std::apply( - [this](auto && ... h) - { - return leaf::try_handle_all( - [this]{return std::move(aw).await_resume();}, - std::move(h)...); - }, std::move(handler)); - } -}; - - - -template -struct [[nodiscard]] try_handle_some_awaitable -{ - Awaitable aw; - std::tuple handler; - - bool await_ready() {return aw.await_ready(); } - template - auto await_suspend(std::coroutine_handle h) {return aw.await_suspend(h);} - - auto await_resume() - { - return std::apply( - [this](auto && ... h) - { - return leaf::try_handle_some( - [this]{return std::move(aw).await_resume();}, - std::move(h)...); - }, std::move(handler)); - } -}; - -} - -#endif //BOOST_COBALT_DETAIL_LEAF_HPP diff --git a/include/boost/cobalt/leaf.hpp b/include/boost/cobalt/leaf.hpp deleted file mode 100644 index a4289154..00000000 --- a/include/boost/cobalt/leaf.hpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2023 Klemens D. Morgenstern -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#ifndef BOOST_COBALT_LEAF_HPP -#define BOOST_COBALT_LEAF_HPP - -#include - -#include -#include - -namespace boost::cobalt -{ - -template -auto try_catch(TryAwaitable && try_coro, H && ... h ) -{ - return detail::try_catch_awaitable< - std::decay_t(try_coro)))>, H...> - { - detail::get_awaitable_type(std::forward(try_coro)), - {std::forward(h)...} - }; -} - -template -auto try_handle_all(TryAwaitable && try_coro, H && ... h ) -{ - return detail::try_handle_all_awaitable< - std::decay_t(try_coro)))>, H...> - { - detail::get_awaitable_type(std::forward(try_coro)), - {std::forward(h)...} - }; -} - -template -auto try_handle_some(TryAwaitable && try_coro, H && ... h ) -{ - return detail::try_handle_some_awaitable< - std::decay_t(try_coro)))>, H...> - { - detail::get_awaitable_type(std::forward(try_coro)), - {std::forward(h)...} - }; -} - -} - -#endif //BOOST_COBALT_LEAF_HPP diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 132f9df5..0e3d995a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,7 +9,7 @@ target_link_libraries(boost_cobalt_static_tests Boost::cobalt) add_executable(boost_cobalt_main EXCLUDE_FROM_ALL main.cpp) add_executable(boost_cobalt_main_compile EXCLUDE_FROM_ALL main_compile.cpp) add_executable(boost_cobalt_basic_tests EXCLUDE_FROM_ALL - async_for.cpp test_main.cpp promise.cpp with.cpp op.cpp handler.cpp join.cpp race.cpp this_coro.cpp leaf.cpp + async_for.cpp test_main.cpp promise.cpp with.cpp op.cpp handler.cpp join.cpp race.cpp this_coro.cpp channel.cpp generator.cpp run.cpp task.cpp gather.cpp wait_group.cpp wrappers.cpp left_race.cpp strand.cpp fork.cpp thread.cpp any_completion_handler.cpp detached.cpp monotonic_resource.cpp sbo_resource.cpp) diff --git a/test/leaf.cpp b/test/leaf.cpp deleted file mode 100644 index 56a2f4be..00000000 --- a/test/leaf.cpp +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright (c) 2023 Klemens D. Morgenstern -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -#include -#include -#include - -#include -#include "test.hpp" - -using namespace boost; - - -BOOST_AUTO_TEST_SUITE(leaf_); - -CO_TEST_CASE(try_catch) -{ - BOOST_CHECK(co_await cobalt::try_catch( - []() -> cobalt::promise - { - throw std::runtime_error("TestException"); - co_return 42; - }(), - [](std::runtime_error & re) - { - BOOST_CHECK(re.what() == std::string("TestException")); - return -1; - }, - [](std::exception &) - { - BOOST_CHECK(false); - return -2; - }) == -1); - - BOOST_CHECK(co_await cobalt::try_catch( - []() -> cobalt::promise - { - co_return 42; - }(), - [](std::runtime_error &) - { - BOOST_CHECK(false); - return -1; - }, - [](std::exception &) - { - BOOST_CHECK(false); - return -2; - }) == 42); -} - - -CO_TEST_CASE(try_handle_all) -{ - BOOST_CHECK(co_await cobalt::try_handle_all( - []() -> cobalt::promise> - { - throw std::runtime_error("TestException"); - co_return 42; - }(), - [](const std::runtime_error & re) - { - BOOST_CHECK(re.what() == std::string("TestException")); - return -1; - }, - [](const std::exception &) - { - BOOST_CHECK(false); - return -2; - }, - [] - { - BOOST_CHECK(false); - return -3; - }) == -1); - - BOOST_CHECK(co_await cobalt::try_handle_all( - []() -> cobalt::promise> - { - co_return 42; - }(), - [](const std::runtime_error &) - { - BOOST_CHECK(false); - return -1; - }, - [](const std::exception &) - { - BOOST_CHECK(false); - return -2; - }, - [] - { - BOOST_CHECK(false); - return -3; - }) == 42); -} - - -CO_TEST_CASE(try_handle_all_) -{ - BOOST_CHECK((co_await cobalt::try_handle_some( - []() -> cobalt::promise> - { - throw std::runtime_error("TestException"); - co_return 42; - }(), - [](const std::runtime_error & re) - { - BOOST_CHECK(re.what() == std::string("TestException")); - return -1; - }, - [](const std::exception &) - { - BOOST_CHECK(false); - return -2; - }, - [] - { - BOOST_CHECK(false); - return -3; - })).value() == -1); - - BOOST_CHECK((co_await cobalt::try_handle_some( - []() -> cobalt::promise> - { - co_return 42; - }(), - [](const std::runtime_error &) - { - BOOST_CHECK(false); - return -1; - }, - [](const std::exception &) - { - BOOST_CHECK(false); - return -2; - }, - [] - { - BOOST_CHECK(false); - return -3; - })).value() == 42); -} - - -BOOST_AUTO_TEST_SUITE_END(); \ No newline at end of file