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