diff --git a/develop/detail/macro_scope.hpp b/develop/detail/macro_scope.hpp index 8316c077d6..9c583bb14e 100644 --- a/develop/detail/macro_scope.hpp +++ b/develop/detail/macro_scope.hpp @@ -41,9 +41,21 @@ #define JSON_TRY try #define JSON_CATCH(exception) catch(exception) #else - #define JSON_THROW(exception) std::abort() - #define JSON_TRY if(true) - #define JSON_CATCH(exception) if(false) + #if !defined(JSON_THROW) + #define JSON_THROW(exception) std::abort() + #else + #define JSON_THROW_USER_PROVIDED + #endif + #if !defined(JSON_TRY) + #define JSON_TRY if(true) + #else + #define JSON_TRY_USER_PROVIDED + #endif + #if !defined(JSON_CATCH) + #define JSON_CATCH(exception) if(false) + #else + #define JSON_CATCH_USER_PROVIDED + #endif #endif // manual branch prediction diff --git a/develop/detail/macro_unscope.hpp b/develop/detail/macro_unscope.hpp index 99a0abdf3b..036743eeaf 100644 --- a/develop/detail/macro_unscope.hpp +++ b/develop/detail/macro_unscope.hpp @@ -9,9 +9,21 @@ #endif // clean up -#undef JSON_CATCH -#undef JSON_THROW -#undef JSON_TRY +#if !defined(JSON_CATCH_USER_PROVIDED) + #undef JSON_CATCH +#else + #undef JSON_CATCH_USER_PROVIDED +#endif +#if !defined(JSON_THROW_USER_PROVIDED) + #undef JSON_THROW +#else + #undef JSON_THROW_USER_PROVIDED +#endif +#if !defined(JSON_TRY_USER_PROVIDED) + #undef JSON_TRY +#else + #undef JSON_TRY_USER_PROVIDED +#endif #undef JSON_LIKELY #undef JSON_UNLIKELY #undef JSON_DEPRECATED diff --git a/src/json.hpp b/src/json.hpp index e12904a889..871c25c224 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -151,9 +151,21 @@ using json = basic_json<>; #define JSON_TRY try #define JSON_CATCH(exception) catch(exception) #else - #define JSON_THROW(exception) std::abort() - #define JSON_TRY if(true) - #define JSON_CATCH(exception) if(false) + #if !defined(JSON_THROW) + #define JSON_THROW(exception) std::abort() + #else + #define JSON_THROW_USER_PROVIDED + #endif + #if !defined(JSON_TRY) + #define JSON_TRY if(true) + #else + #define JSON_TRY_USER_PROVIDED + #endif + #if !defined(JSON_CATCH) + #define JSON_CATCH(exception) if(false) + #else + #define JSON_CATCH_USER_PROVIDED + #endif #endif // manual branch prediction @@ -17131,9 +17143,21 @@ inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std #endif // clean up -#undef JSON_CATCH -#undef JSON_THROW -#undef JSON_TRY +#if !defined(JSON_CATCH_USER_PROVIDED) + #undef JSON_CATCH +#else + #undef JSON_CATCH_USER_PROVIDED +#endif +#if !defined(JSON_THROW_USER_PROVIDED) + #undef JSON_THROW +#else + #undef JSON_THROW_USER_PROVIDED +#endif +#if !defined(JSON_TRY_USER_PROVIDED) + #undef JSON_TRY +#else + #undef JSON_TRY_USER_PROVIDED +#endif #undef JSON_LIKELY #undef JSON_UNLIKELY #undef JSON_DEPRECATED