};
// given an error code - return the action code which it corresponds to.
-constexpr safe_numerics_actions
+constexpr inline safe_numerics_actions
make_safe_numerics_action(const safe_numerics_error & e){
// we can't use standard algorithms since we want this to be constexpr
// this brute force solution is simple and pretty fast anyway
return safe_numerics_actions::no_action;
}
-////////////////////////////////////////////////////////////////////////////////
-// compile time error dispatcher
-
-// note slightly baroque implementation of a compile time switch statement
-// which instatiates only those cases which are actually invoked. This is
-// motivated to implement the "trap" functionality which will generate a syntax
-// error if and only a function which might fail is called.
-
-namespace dispatch_switch {
-
- template<class EP, safe_numerics_actions>
- struct dispatch_case {};
-
- template<class EP>
- struct dispatch_case<EP, safe_numerics_actions::uninitialized_value> {
- constexpr static void invoke(const safe_numerics_error & e, const char * msg){
- EP::on_uninitialized_value(e, msg);
- }
- };
- template<class EP>
- struct dispatch_case<EP, safe_numerics_actions::arithmetic_error> {
- constexpr static void invoke(const safe_numerics_error & e, const char * msg){
- EP::on_arithmetic_error(e, msg);
- }
- };
- template<class EP>
- struct dispatch_case<EP, safe_numerics_actions::implementation_defined_behavior> {
- constexpr static void invoke(const safe_numerics_error & e, const char * msg){
- EP::on_implementation_defined_behavior(e, msg);
- }
- };
- template<class EP>
- struct dispatch_case<EP, safe_numerics_actions::undefined_behavior> {
- constexpr static void invoke(const safe_numerics_error & e, const char * msg){
- EP::on_undefined_behavior(e, msg);
- }
- };
-
-} // dispatch_switch
-
-template<class EP, safe_numerics_error E>
-constexpr void
-dispatch(const char * msg){
- constexpr safe_numerics_actions a = make_safe_numerics_action(E);
- dispatch_switch::dispatch_case<EP, a>::invoke(E, msg);
-}
-
-template<class EP, class R>
-class dispatch_and_return {
-public:
- template<safe_numerics_error E>
- constexpr static checked_result<R> invoke(
- char const * const & msg
- ) {
- dispatch<EP, E>(msg);
- return checked_result<R>(E, msg);
- }
-};
-
////////////////////////////////////////////////////////////////////////////////
// pre-made error policy classes