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/stop_requested_exception.hpp>  
14   #include <boost/capy/detail/config.hpp> 13   #include <boost/capy/detail/config.hpp>
15   14  
16   #include <concepts> 15   #include <concepts>
17   #include <exception> 16   #include <exception>
18   #include <type_traits> 17   #include <type_traits>
19   #include <utility> 18   #include <utility>
20   19  
21   namespace boost { 20   namespace boost {
22   namespace capy { 21   namespace capy {
23   namespace detail { 22   namespace detail {
24   23  
25   struct default_handler 24   struct default_handler
26   { 25   {
27   template<class T> 26   template<class T>
HITCBC 28   104 void operator()(T&&) const noexcept 27   104 void operator()(T&&) const noexcept
29   { 28   {
HITCBC 30   104 } 29   104 }
31   30  
HITCBC 32   3464 void operator()() const noexcept 31   3449 void operator()() const noexcept
33   { 32   {
HITCBC 34   3464 } 33   3449 }
35   34  
  35 + // An unhandled exception propagates to the trampoline's
  36 + // unhandled_exception, which terminates.
HITCBC 36   344 void operator()(std::exception_ptr ep) const 37   336 void operator()(std::exception_ptr ep) const
37   { 38   {
HITCBC 38 - 344 if(!ep) 39 + 336 if(ep)
DCB 39 - 1 return;  
40 - try  
41 - {  
DCB 42 - 686 }  
43 - catch(stop_requested_exception const&)  
DCB 44 - 343 {  
45 - // Cancellation is a normal completion, not an error.  
46 - }  
DCB 47 - 5 // A real unhandled exception propagates to the trampoline's  
48 - // unhandled_exception, which terminates.  
HITGIC 49   std::rethrow_exception(ep); 40   335 std::rethrow_exception(ep);
HITGIC 50   } 41   1 }
51   }; 42   };
52   43  
53   template<class H1, class H2> 44   template<class H1, class H2>
54   struct handler_pair 45   struct handler_pair
55   { 46   {
56   static_assert( 47   static_assert(
57   std::is_nothrow_move_constructible_v<H1> && 48   std::is_nothrow_move_constructible_v<H1> &&
58   std::is_nothrow_move_constructible_v<H2>, 49   std::is_nothrow_move_constructible_v<H2>,
59   "Handlers must be nothrow move constructible"); 50   "Handlers must be nothrow move constructible");
60   51  
61   H1 h1_; 52   H1 h1_;
62   H2 h2_; 53   H2 h2_;
63   54  
64   template<class T> 55   template<class T>
HITCBC 65   80 void operator()(T&& v) 56   80 void operator()(T&& v)
66   { 57   {
HITCBC 67   80 h1_(std::forward<T>(v)); 58   80 h1_(std::forward<T>(v));
HITCBC 68   80 } 59   80 }
69   60  
HITCBC 70   19 void operator()() 61   12 void operator()()
71   { 62   {
HITCBC 72   19 h1_(); 63   12 h1_();
HITCBC 73   19 } 64   12 }
74   65  
HITCBC 75   36 void operator()(std::exception_ptr ep) 66   28 void operator()(std::exception_ptr ep)
76   { 67   {
HITCBC 77   36 h2_(ep); 68   28 h2_(ep);
HITCBC 78   36 } 69   28 }
79   }; 70   };
80   71  
81   template<class H1> 72   template<class H1>
82   struct handler_pair<H1, default_handler> 73   struct handler_pair<H1, default_handler>
83   { 74   {
84   static_assert( 75   static_assert(
85   std::is_nothrow_move_constructible_v<H1>, 76   std::is_nothrow_move_constructible_v<H1>,
86   "Handler must be nothrow move constructible"); 77   "Handler must be nothrow move constructible");
87   78  
88   H1 h1_; 79   H1 h1_;
89   80  
90   template<class T> 81   template<class T>
HITCBC 91   165 void operator()(T&& v) 82   153 void operator()(T&& v)
92   { 83   {
HITCBC 93   165 h1_(std::forward<T>(v)); 84   153 h1_(std::forward<T>(v));
HITCBC 94   165 } 85   153 }
95   86  
HITCBC 96   2006 void operator()() 87   2004 void operator()()
97   { 88   {
HITCBC 98   2006 h1_(); 89   2004 h1_();
HITCBC 99   2006 } 90   2004 }
100   91  
HITCBC 101   679 void operator()(std::exception_ptr ep) 92   673 void operator()(std::exception_ptr ep)
102   { 93   {
103   if constexpr(std::invocable<H1, std::exception_ptr>) 94   if constexpr(std::invocable<H1, std::exception_ptr>)
HITCBC 104   678 h1_(ep); 95   672 h1_(ep);
105   else 96   else
HITCBC 106   2 default_handler{}(ep); 97   2 default_handler{}(ep);
HITCBC 107   342 } 98   339 }
108   }; 99   };
109   100  
110   } // namespace detail 101   } // namespace detail
111   } // namespace capy 102   } // namespace capy
112   } // namespace boost 103   } // namespace boost
113   104  
114   #endif 105   #endif