diff --git a/doc/mkdocs/docs/features/macros.md b/doc/mkdocs/docs/features/macros.md index d324a1325..d02bd8083 100644 --- a/doc/mkdocs/docs/features/macros.md +++ b/doc/mkdocs/docs/features/macros.md @@ -4,16 +4,41 @@ Some aspects of the library can be configured by defining preprocessor macros be ## `JSON_ASSERT(x)` -The default value is `#!cpp assert(x)`. +This marco controls which code is executed for runtime assertions of the libraries. + +!!! info "Default behavior" + + The default value is [`#!cpp assert(x)`](https://en.cppreference.com/w/cpp/error/assert). + + ```cpp + #define JSON_ASSERT(x) assert(x) + ``` ## `JSON_CATCH_USER(exception)` -This macro overrides `#!cpp catch` calls inside the library. The argument is the type of the exception to catch. As of -version 3.8.0, the library only catches `std::out_of_range` exceptions internally to rethrow them as -[`json::out_of_range`](../home/exceptions.md#out-of-range) exceptions. The macro is always followed by a scope. +This macro overrides [`#!cpp catch`](https://en.cppreference.com/w/cpp/language/try_catch) calls inside the library. +The argument is the type of the exception to catch. As of version 3.8.0, the library only catches `std::out_of_range` +exceptions internally to rethrow them as [`json::out_of_range`](../home/exceptions.md#out-of-range) exceptions. The +macro is always followed by a scope. See [Switch off exceptions](../home/exceptions.md#switch-off-exceptions) for an example. +!!! info "Default behavior" + + When exceptions are enabled, the default value is + [`#!cpp catch(exception)`](https://en.cppreference.com/w/cpp/language/try_catch). + + ```cpp + #define JSON_CATCH_USER(exception) catch(exception) + ``` + + When exceptions are switched off by the compiler, the default value is `#!cpp if (false)` to make the catch block + unreachable. + + ```cpp + #define JSON_CATCH_USER(exception) if (false) + ``` + ## `JSON_DIAGNOSTICS` This macro enables extended diagnostics for exception messages. Possible values are `1` to enable or `0` to disable @@ -26,6 +51,12 @@ that enabling this macro increases the size of every JSON value by one pointer a The diagnostics messages can also be controlled with the CMake option `JSON_Diagnostics` (`OFF` by default) which sets `JSON_DIAGNOSTICS` accordingly. +!!! info "Default behavior" + + ```cpp + #define JSON_DIAGNOSTICS 0 + ``` + ## `JSON_HAS_CPP_11`, `JSON_HAS_CPP_14`, `JSON_HAS_CPP_17`, `JSON_HAS_CPP_20` The library targets C++11, but also supports some features introduced in later C++ versions (e.g., `std::string_view` @@ -34,6 +65,11 @@ standard. By defining any of these symbols, the internal check is overridden and unconditionally assumed. This can be helpful for compilers that only implement parts of the standard and would be detected incorrectly. +!!! info "Default behavior" + + The default value is detected based on the preprocessor macros `#!cpp __cplusplus`, `#!cpp _HAS_CXX17`, or + `#!cpp _MSVC_LANG`. + ## `JSON_HAS_FILESYSTEM`, `JSON_HAS_EXPERIMENTAL_FILESYSTEM` When compiling with C++17, the library provides conversions from and to `std::filesystem::path`. As compiler support @@ -41,12 +77,29 @@ for filesystem is limited, the library tries to detect whether ``/`s or ``/`std::experimental::filesystem` (`JSON_HAS_EXPERIMENTAL_FILESYSTEM`) should be used. To override the built-in check, define `JSON_HAS_FILESYSTEM` or `JSON_HAS_EXPERIMENTAL_FILESYSTEM` to `1`. +!!! info "Default behavior" + + The default value is detected based on the preprocessor macros `#!cpp __cpp_lib_filesystem`, + `#!cpp __cpp_lib_experimental_filesystem`, `#!cpp __has_include()`, or + `#!cpp __has_include()`. + +Note that older compilers or older versions of libstd++ also require the library `stdc++fs` to be linked to for +filesystem support. + ## `JSON_NOEXCEPTION` Exceptions can be switched off by defining the symbol `JSON_NOEXCEPTION`. When defining `JSON_NOEXCEPTION`, `#!cpp try` is replaced by `#!cpp if (true)`, `#!cpp catch` is replaced by `#!cpp if (false)`, and `#!cpp throw` is replaced by `#!cpp std::abort()`. +!!! info "Default behavior" + + By default, the macro is not defined. + + ```cpp + #undef JSON_NOEXCEPTION + ``` + The same effect is achieved by setting the compiler flag `-fno-exceptions`. Note the explanatory [`what()`](https://en.cppreference.com/w/cpp/error/exception/what) string of exceptions is not @@ -58,23 +111,72 @@ When defined, headers ``, ``, ``, ``, and `