Skip to content

Commit

Permalink
Allow overriding THROW/CATCH/TRY macros with no-exceptions #938
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaido committed Jan 28, 2018
1 parent 52e9449 commit c9d349f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 12 deletions.
18 changes: 15 additions & 3 deletions develop/detail/macro_scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 15 additions & 3 deletions develop/detail/macro_unscope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 30 additions & 6 deletions src/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c9d349f

Please sign in to comment.