leaf.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright (c) 2023 Klemens D. Morgenstern
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_COBALT_LEAF_HPP
  6. #define BOOST_COBALT_LEAF_HPP
  7. #include <boost/cobalt/detail/leaf.hpp>
  8. #include <boost/leaf/config.hpp>
  9. #include <boost/leaf/handle_errors.hpp>
  10. namespace boost::cobalt
  11. {
  12. template<awaitable TryAwaitable, typename ... H >
  13. auto try_catch(TryAwaitable && try_coro, H && ... h )
  14. {
  15. return detail::try_catch_awaitable<
  16. std::decay_t<decltype(detail::get_awaitable_type(std::forward<TryAwaitable>(try_coro)))>, H...>
  17. {
  18. detail::get_awaitable_type(std::forward<TryAwaitable>(try_coro)),
  19. {std::forward<H>(h)...}
  20. };
  21. }
  22. template<awaitable TryAwaitable, typename ... H >
  23. auto try_handle_all(TryAwaitable && try_coro, H && ... h )
  24. {
  25. return detail::try_handle_all_awaitable<
  26. std::decay_t<decltype(detail::get_awaitable_type(std::forward<TryAwaitable>(try_coro)))>, H...>
  27. {
  28. detail::get_awaitable_type(std::forward<TryAwaitable>(try_coro)),
  29. {std::forward<H>(h)...}
  30. };
  31. }
  32. template<awaitable TryAwaitable, typename ... H >
  33. auto try_handle_some(TryAwaitable && try_coro, H && ... h )
  34. {
  35. return detail::try_handle_some_awaitable<
  36. std::decay_t<decltype(detail::get_awaitable_type(std::forward<TryAwaitable>(try_coro)))>, H...>
  37. {
  38. detail::get_awaitable_type(std::forward<TryAwaitable>(try_coro)),
  39. {std::forward<H>(h)...}
  40. };
  41. }
  42. }
  43. #endif //BOOST_COBALT_LEAF_HPP