include/boost/capy/detail/run_callbacks.hpp
92.6% Lines (25/27)
52.6% Functions (229/435)
include/boost/capy/detail/run_callbacks.hpp
| Line | Hits | Source Code |
|---|---|---|
| 1 | // | |
| 2 | // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) | |
| 3 | // | |
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
| 6 | // | |
| 7 | // Official repository: https://github.com/cppalliance/capy | |
| 8 | // | |
| 9 | ||
| 10 | #ifndef BOOST_CAPY_DETAIL_RUN_CALLBACKS_HPP | |
| 11 | #define BOOST_CAPY_DETAIL_RUN_CALLBACKS_HPP | |
| 12 | ||
| 13 | #include <boost/capy/detail/config.hpp> | |
| 14 | ||
| 15 | #include <concepts> | |
| 16 | #include <exception> | |
| 17 | #include <type_traits> | |
| 18 | #include <utility> | |
| 19 | ||
| 20 | namespace boost { | |
| 21 | namespace capy { | |
| 22 | namespace detail { | |
| 23 | ||
| 24 | struct default_handler | |
| 25 | { | |
| 26 | template<class T> | |
| 27 | 2 | void operator()(T&&) const noexcept |
| 28 | { | |
| 29 | 2 | } |
| 30 | ||
| 31 | 1720 | void operator()() const noexcept |
| 32 | { | |
| 33 | 1720 | } |
| 34 | ||
| 35 | 1000 | void operator()(std::exception_ptr ep) const |
| 36 | { | |
| 37 | 1000 | if(ep) |
| 38 | 1000 | std::rethrow_exception(ep); |
| 39 | ✗ | } |
| 40 | }; | |
| 41 | ||
| 42 | template<class H1, class H2> | |
| 43 | struct handler_pair | |
| 44 | { | |
| 45 | static_assert( | |
| 46 | std::is_nothrow_move_constructible_v<H1> && | |
| 47 | std::is_nothrow_move_constructible_v<H2>, | |
| 48 | "Handlers must be nothrow move constructible"); | |
| 49 | ||
| 50 | H1 h1_; | |
| 51 | H2 h2_; | |
| 52 | ||
| 53 | template<class T> | |
| 54 | 77 | void operator()(T&& v) |
| 55 | { | |
| 56 | 77 | h1_(std::forward<T>(v)); |
| 57 | 77 | } |
| 58 | ||
| 59 | 5 | void operator()() |
| 60 | { | |
| 61 | 5 | h1_(); |
| 62 | 5 | } |
| 63 | ||
| 64 | 26 | void operator()(std::exception_ptr ep) |
| 65 | { | |
| 66 | 26 | h2_(ep); |
| 67 | 26 | } |
| 68 | }; | |
| 69 | ||
| 70 | template<class H1> | |
| 71 | struct handler_pair<H1, default_handler> | |
| 72 | { | |
| 73 | static_assert( | |
| 74 | std::is_nothrow_move_constructible_v<H1>, | |
| 75 | "Handler must be nothrow move constructible"); | |
| 76 | ||
| 77 | H1 h1_; | |
| 78 | ||
| 79 | template<class T> | |
| 80 | 102 | void operator()(T&& v) |
| 81 | { | |
| 82 | 102 | h1_(std::forward<T>(v)); |
| 83 | 102 | } |
| 84 | ||
| 85 | 3443 | void operator()() |
| 86 | { | |
| 87 | 3443 | h1_(); |
| 88 | 3443 | } |
| 89 | ||
| 90 | 2005 | void operator()(std::exception_ptr ep) |
| 91 | { | |
| 92 | if constexpr(std::invocable<H1, std::exception_ptr>) | |
| 93 | 2005 | h1_(ep); |
| 94 | else | |
| 95 | ✗ | std::rethrow_exception(ep); |
| 96 | 1005 | } |
| 97 | }; | |
| 98 | ||
| 99 | } // namespace detail | |
| 100 | } // namespace capy | |
| 101 | } // namespace boost | |
| 102 | ||
| 103 | #endif | |
| 104 |