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 + // Copyright (c) 2026 Michael Vandeberg
3   // 4   //
4   // Distributed under the Boost Software License, Version 1.0. (See accompanying 5   // 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   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6   // 7   //
7   // Official repository: https://github.com/cppalliance/capy 8   // Official repository: https://github.com/cppalliance/capy
8   // 9   //
9   10  
10   #ifndef BOOST_CAPY_DETAIL_RUN_CALLBACKS_HPP 11   #ifndef BOOST_CAPY_DETAIL_RUN_CALLBACKS_HPP
11   #define BOOST_CAPY_DETAIL_RUN_CALLBACKS_HPP 12   #define BOOST_CAPY_DETAIL_RUN_CALLBACKS_HPP
12   13  
13   #include <boost/capy/detail/config.hpp> 14   #include <boost/capy/detail/config.hpp>
14 - #include <boost/capy/detail/stop_requested_exception.hpp> 15 + #include <boost/capy/detail/quitter_stopped.hpp>
15   16  
16   #include <concepts> 17   #include <concepts>
17   #include <exception> 18   #include <exception>
18   #include <type_traits> 19   #include <type_traits>
19   #include <utility> 20   #include <utility>
20   21  
21   namespace boost { 22   namespace boost {
22   namespace capy { 23   namespace capy {
23   namespace detail { 24   namespace detail {
24   25  
25   struct default_handler 26   struct default_handler
26   { 27   {
27   template<class T> 28   template<class T>
HITCBC 28   104 void operator()(T&&) const noexcept 29   104 void operator()(T&&) const noexcept
29   { 30   {
HITCBC 30   104 } 31   104 }
31   32  
HITCBC 32   3445 void operator()() const noexcept 33   3479 void operator()() const noexcept
33   { 34   {
HITCBC 34   3445 } 35   3479 }
35   36  
HITCBC 36   344 void operator()(std::exception_ptr ep) const 37   348 void operator()(std::exception_ptr ep) const
37   { 38   {
HITCBC 38   344 if(!ep) 39   348 if(!ep)
HITCBC 39   1 return; 40   1 return;
40   try 41   try
41   { 42   {
HITCBC 42   686 std::rethrow_exception(ep); 43   694 std::rethrow_exception(ep);
43   } 44   }
HITCBC 44 - 343 catch(stop_requested_exception const&) 45 + 347 catch(quitter_stopped const&)
45   { 46   {
46 - // Cancellation is a normal completion, not an error. 47 + // A quitter's stop is not an error.
HITCBC 47   5 } 48   9 }
48 - // A real unhandled exception propagates to the trampoline's 49 + // Any other exception propagates to the trampoline's
49   // unhandled_exception, which terminates. 50   // unhandled_exception, which terminates.
50   } 51   }
51   }; 52   };
52   53  
53   template<class H1, class H2> 54   template<class H1, class H2>
54   struct handler_pair 55   struct handler_pair
55   { 56   {
56   static_assert( 57   static_assert(
57   std::is_nothrow_move_constructible_v<H1> && 58   std::is_nothrow_move_constructible_v<H1> &&
58   std::is_nothrow_move_constructible_v<H2>, 59   std::is_nothrow_move_constructible_v<H2>,
59   "Handlers must be nothrow move constructible"); 60   "Handlers must be nothrow move constructible");
60   61  
61   H1 h1_; 62   H1 h1_;
62   H2 h2_; 63   H2 h2_;
63   64  
64   template<class T> 65   template<class T>
HITCBC 65   80 void operator()(T&& v) 66   83 void operator()(T&& v)
66   { 67   {
HITCBC 67   80 h1_(std::forward<T>(v)); 68   83 h1_(std::forward<T>(v));
HITCBC 68   80 } 69   83 }
69   70  
HITCBC 70   19 void operator()() 71   10024 void operator()()
71   { 72   {
HITCBC 72   19 h1_(); 73   10024 h1_();
HITCBC 73   19 } 74   10024 }
74   75  
HITCBC 75   36 void operator()(std::exception_ptr ep) 76   44 void operator()(std::exception_ptr ep)
76   { 77   {
HITCBC 77   36 h2_(ep); 78   44 h2_(ep);
HITCBC 78   36 } 79   44 }
79   }; 80   };
80   81  
81   template<class H1> 82   template<class H1>
82   struct handler_pair<H1, default_handler> 83   struct handler_pair<H1, default_handler>
83   { 84   {
84   static_assert( 85   static_assert(
85   std::is_nothrow_move_constructible_v<H1>, 86   std::is_nothrow_move_constructible_v<H1>,
86   "Handler must be nothrow move constructible"); 87   "Handler must be nothrow move constructible");
87   88  
88   H1 h1_; 89   H1 h1_;
89   90  
90   template<class T> 91   template<class T>
HITCBC 91   165 void operator()(T&& v) 92   167 void operator()(T&& v)
92   { 93   {
HITCBC 93   165 h1_(std::forward<T>(v)); 94   167 h1_(std::forward<T>(v));
HITCBC 94   165 } 95   167 }
95   96  
HITCBC 96   2006 void operator()() 97   2008 void operator()()
97   { 98   {
HITCBC 98   2006 h1_(); 99   2008 h1_();
HITCBC 99   2006 } 100   2008 }
100   101  
HITCBC 101   679 void operator()(std::exception_ptr ep) 102   681 void operator()(std::exception_ptr ep)
102   { 103   {
103   if constexpr(std::invocable<H1, std::exception_ptr>) 104   if constexpr(std::invocable<H1, std::exception_ptr>)
HITCBC 104   678 h1_(ep); 105   679 h1_(ep);
105   else 106   else
HITCBC 106   2 default_handler{}(ep); 107   3 default_handler{}(ep);
HITCBC 107   342 } 108   344 }
108   }; 109   };
109   110  
110   } // namespace detail 111   } // namespace detail
111   } // namespace capy 112   } // namespace capy
112   } // namespace boost 113   } // namespace boost
113   114  
114   #endif 115   #endif