100.00% Lines (29/29) 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 + #include <boost/capy/detail/stop_requested_exception.hpp>
14   15  
15   #include <concepts> 16   #include <concepts>
16   #include <exception> 17   #include <exception>
17   #include <type_traits> 18   #include <type_traits>
18   #include <utility> 19   #include <utility>
19   20  
20   namespace boost { 21   namespace boost {
21   namespace capy { 22   namespace capy {
22   namespace detail { 23   namespace detail {
23   24  
24   struct default_handler 25   struct default_handler
25   { 26   {
26   template<class T> 27   template<class T>
HITCBC 27   3 void operator()(T&&) const noexcept 28   3 void operator()(T&&) const noexcept
28   { 29   {
HITCBC 29   3 } 30   3 }
30   31  
HITCBC 31   1851 void operator()() const noexcept 32   1857 void operator()() const noexcept
32   { 33   {
HITCBC 33   1851 } 34   1857 }
34   35  
HITCBC 35   1033 void operator()(std::exception_ptr ep) const 36   1037 void operator()(std::exception_ptr ep) const
36   { 37   {
HITCBC 37 - 1033 if(ep) 38 + 1037 if(!ep)
HITGNC   39 + 1 return;
  40 + try
  41 + {
HITCBC 38   1032 std::rethrow_exception(ep); 42   2072 std::rethrow_exception(ep);
  43 + }
HITGNC   44 + 1036 catch(stop_requested_exception const&)
  45 + {
  46 + // Cancellation is a normal completion, not an error.
HITGNC   47 + 6 }
ECB 39   1 } 48   }
40   }; 49   };
41   50  
42   template<class H1, class H2> 51   template<class H1, class H2>
43   struct handler_pair 52   struct handler_pair
44   { 53   {
45   static_assert( 54   static_assert(
46   std::is_nothrow_move_constructible_v<H1> && 55   std::is_nothrow_move_constructible_v<H1> &&
47   std::is_nothrow_move_constructible_v<H2>, 56   std::is_nothrow_move_constructible_v<H2>,
48   "Handlers must be nothrow move constructible"); 57   "Handlers must be nothrow move constructible");
49   58  
50   H1 h1_; 59   H1 h1_;
51   H2 h2_; 60   H2 h2_;
52   61  
53   template<class T> 62   template<class T>
HITCBC 54   80 void operator()(T&& v) 63   80 void operator()(T&& v)
55   { 64   {
HITCBC 56   80 h1_(std::forward<T>(v)); 65   80 h1_(std::forward<T>(v));
HITCBC 57   80 } 66   80 }
58   67  
HITCBC 59   21 void operator()() 68   21 void operator()()
60   { 69   {
HITCBC 61   21 h1_(); 70   21 h1_();
HITCBC 62   21 } 71   21 }
63   72  
HITCBC 64   31 void operator()(std::exception_ptr ep) 73   32 void operator()(std::exception_ptr ep)
65   { 74   {
HITCBC 66   31 h2_(ep); 75   32 h2_(ep);
HITCBC 67   31 } 76   31 }
68   }; 77   };
69   78  
70   template<class H1> 79   template<class H1>
71   struct handler_pair<H1, default_handler> 80   struct handler_pair<H1, default_handler>
72   { 81   {
73   static_assert( 82   static_assert(
74   std::is_nothrow_move_constructible_v<H1>, 83   std::is_nothrow_move_constructible_v<H1>,
75   "Handler must be nothrow move constructible"); 84   "Handler must be nothrow move constructible");
76   85  
77   H1 h1_; 86   H1 h1_;
78   87  
79   template<class T> 88   template<class T>
HITCBC 80   137 void operator()(T&& v) 89   137 void operator()(T&& v)
81   { 90   {
HITCBC 82   137 h1_(std::forward<T>(v)); 91   137 h1_(std::forward<T>(v));
HITCBC 83   137 } 92   137 }
84   93  
HITCBC 85   3565 void operator()() 94   3565 void operator()()
86   { 95   {
HITCBC 87   3565 h1_(); 96   3565 h1_();
HITCBC 88   3565 } 97   3565 }
89   98  
HITCBC 90   2059 void operator()(std::exception_ptr ep) 99   2059 void operator()(std::exception_ptr ep)
91   { 100   {
92   if constexpr(std::invocable<H1, std::exception_ptr>) 101   if constexpr(std::invocable<H1, std::exception_ptr>)
HITCBC 93   2058 h1_(ep); 102   2058 h1_(ep);
94   else 103   else
HITCBC 95 - 1 std::rethrow_exception(ep); 104 + 2 default_handler{}(ep);
HITCBC 96   1032 } 105   1032 }
97   }; 106   };
98   107  
99   } // namespace detail 108   } // namespace detail
100   } // namespace capy 109   } // namespace capy
101   } // namespace boost 110   } // namespace boost
102   111  
103   #endif 112   #endif