1010
1111#include " daw/daw_arith_traits.h"
1212#include " daw/daw_attributes.h"
13+ #include " daw/daw_check_exceptions.h"
14+ #include " daw/daw_cpp_feature_check.h"
1315
1416#include < exception>
1517#include < memory>
@@ -34,29 +36,33 @@ namespace daw::integers {
3436
3537 namespace sint_impl {
3638 inline auto &get_signed_integer_overflow_handler ( ) {
37- static struct handler_t {
39+ static DAW_CONSTINIT struct handler_t {
3840 signed_int_error_handler_t cb = nullptr ;
3941 void *data = nullptr ;
4042 } handler{ };
4143 return handler;
4244 }
4345
4446 inline auto &get_signed_integer_div_by_zero_handler ( ) {
45- static struct handler_t {
47+ static DAW_CONSTINIT struct handler_t {
4648 signed_int_error_handler_t cb = nullptr ;
4749 void *data = nullptr ;
4850 } handler{ };
4951 return handler;
5052 }
5153 } // namespace sint_impl
5254
55+ // / Caller is responsible for ensuring that this is called in a context that
56+ // / protects against multiple threads accessing/writing at the same time
5357 DAW_ATTRIB_NOINLINE inline void register_signed_overflow_handler (
5458 signed_int_error_handler_t handler = nullptr ,
5559 void *data = nullptr ) noexcept {
5660 sint_impl::get_signed_integer_overflow_handler ( ).cb = handler;
5761 sint_impl::get_signed_integer_overflow_handler ( ).data = data;
5862 }
5963
64+ // / Caller is responsible for ensuring that this is called in a context that
65+ // / protects against multiple threads accessing/writing at the same time
6066 template <typename Func,
6167 std::enable_if_t <std::is_class_v<Func> and
6268 std::is_invocable_v<Func, SignedIntegerErrorType>,
@@ -79,13 +85,17 @@ namespace daw::integers {
7985 }
8086 }
8187
88+ // / Caller is responsible for ensuring that this is called in a context that
89+ // / protects against multiple threads accessing/writing at the same time
8290 DAW_ATTRIB_NOINLINE inline void register_signed_div_by_zero_handler (
8391 signed_int_error_handler_t handler = nullptr ,
8492 void *data = nullptr ) noexcept {
8593 sint_impl::get_signed_integer_div_by_zero_handler ( ).cb = handler;
8694 sint_impl::get_signed_integer_div_by_zero_handler ( ).data = data;
8795 }
8896
97+ // / Caller is responsible for ensuring that this is called in a context that
98+ // / protects against multiple threads accessing/writing at the same time
8999 template <typename Func,
90100 std::enable_if_t <std::is_class_v<Func> and
91101 std::is_invocable_v<Func, SignedIntegerErrorType>,
@@ -117,7 +127,7 @@ namespace daw::integers {
117127 handler.cb ( handler.data , SignedIntegerErrorType::Overflow );
118128 return ;
119129 }
120- throw signed_integer_overflow_exception ( );
130+ DAW_THROW_OR_TERMINATE_NA ( signed_integer_overflow_exception );
121131 }
122132
123133 DAW_ATTRIB_NOINLINE inline void on_signed_integer_div_by_zero ( ) {
@@ -126,6 +136,6 @@ namespace daw::integers {
126136 handler.cb ( handler.data , SignedIntegerErrorType::DivideByZero );
127137 return ;
128138 }
129- throw signed_integer_div_by_zero_exception ( );
139+ DAW_THROW_OR_TERMINATE_NA ( signed_integer_div_by_zero_exception );
130140 }
131141} // namespace daw::integers
0 commit comments