Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
c6740d7d
Unverified
Commit
c6740d7d
authored
Jan 11, 2022
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
📝
add documentation for default behavior for macros
parent
ef556019
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
112 additions
and
4 deletions
+112
-4
doc/mkdocs/docs/features/macros.md
doc/mkdocs/docs/features/macros.md
+112
-4
No files found.
doc/mkdocs/docs/features/macros.md
View file @
c6740d7d
...
...
@@ -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 `<filesystem>`/`s
or
`<experimental/filesystem>`
/
`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(<filesystem>)`, or
`#!cpp __has_include(<experimental/filesystem>)`.
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 `<cstdio>`, `<ios>`, `<iosfwd>`, `<istream>`, and `<ostrea
relying on these headers are excluded. This is relevant for environment where these I/O functions are disallowed for
security reasons (e.g., Intel Software Guard Extensions (SGX)).
!!! info "Default behavior"
By default, the macro is not defined.
```cpp
#undef JSON_NO_IO
```
## `JSON_SKIP_UNSUPPORTED_COMPILER_CHECK`
When defined, the library will not create a compile error when a known unsupported compiler is detected. This allows to
use the library with compilers that do not fully support C++11 and may only work if unsupported features are not used.
!!! info "Default behavior"
By default, the macro is not defined.
```cpp
#undef JSON_SKIP_UNSUPPORTED_COMPILER_CHECK
```
## `JSON_THROW_USER(exception)`
This macro overrides
`#!cpp throw`
calls inside the library. The argument is the exception to be thrown. Note that
`JSON_THROW_USER`
should leave the current scope (e.g., by throwing or aborting), as continuing after it may yield
undefined behavior.
!!! info "Default behavior"
When exceptions are enabled, the default value is
[`#!cpp throw exception`](https://en.cppreference.com/w/cpp/language/throw).
```cpp
#define JSON_THROW_USER(exception) throw exception
```
When exceptions are switched off by the compiler, the default value is
[`#!cpp std::abort()`](https://en.cppreference.com/w/cpp/utility/program/abort) to make reaching the throw branch
abort the process.
```cpp
#define JSON_THROW_USER(exception) std::abort()
```
See
[
Switch off exceptions
](
../home/exceptions.md#switch-off-exceptions
)
for an example.
## `JSON_TRY_USER`
This macro overrides
`#!cpp try`
calls inside the library. It has no arguments and is always followed by a scope.
!!! info "Default behavior"
When exceptions are enabled, the default value is
[`#!cpp try`](https://en.cppreference.com/w/cpp/language/try_catch).
```cpp
#define JSON_TRY_USER try
```
When exceptions are switched off by the compiler, the default value is `#!cpp if (true)` to unconditionally execute
the following code block.
```cpp
#define JSON_TRY_USER if (true)
```
See
[
Switch off exceptions
](
../home/exceptions.md#switch-off-exceptions
)
for an example.
## `JSON_USE_IMPLICIT_CONVERSIONS`
...
...
@@ -101,6 +203,12 @@ When defined to `0`, implicit conversions are switched off. By default, implicit
Implicit conversions can also be controlled with the CMake option
`JSON_ImplicitConversions`
(
`ON`
by default) which
sets
`JSON_USE_IMPLICIT_CONVERSIONS`
accordingly.
!!! info "Default behavior"
```cpp
#define JSON_USE_IMPLICIT_CONVERSIONS 1
```
## `NLOHMANN_DEFINE_TYPE_INTRUSIVE(type, member...)`
This macro can be used to simplify the serialization/deserialization of types if (1) want to use a JSON object as
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment