docs: correct assertion conditions and remove stale diagnostic locations (#6131)

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Aditya Singh Bakawat authored and GitHub committed 2026-11-18 08:56:51 +01:00
1 parent 0ac14610d6
commit 8c3335d41f
2 files changed
+11 -25

No files matched your search

+3 -5
View File
@@ -47,11 +47,9 @@ Therefore, assertions can be switched off by defining `NDEBUG`.
} }
``` ```
Output: The assertion `#!cpp it != m_data.m_value.object->end()` fails in `#!cpp operator[]`.
The exact diagnostic format, source filename, and line number depend on the platform,
``` library version, and whether the single-header or multi-header version is used.
Assertion failed: (m_value.object->find(key) != m_value.object->end()), function operator[], file json.hpp, line 2144.
```
??? example "Example: user-defined behavior" ??? example "Example: user-defined behavior"
+8 -20
View File
@@ -18,6 +18,10 @@ before including the `json.hpp` header.
## Function with runtime assertions ## Function with runtime assertions
The examples below identify the failing assertion and the function containing it.
The exact diagnostic format, source filename, and line number depend on the platform,
library version, and whether the single-header or multi-header version is used.
### Unchecked access to a const value ### Unchecked access to a const value
Function [`operator[]`](../api/basic_json/operator%5B%5D.md) implements unchecked access for arrays and objects. Whereas Function [`operator[]`](../api/basic_json/operator%5B%5D.md) implements unchecked access for arrays and objects. Whereas
@@ -46,11 +50,7 @@ See also the documentation on [element access](element_access/index.md).
} }
``` ```
Output: The assertion `#!cpp it != m_data.m_value.object->end()` fails in `#!cpp operator[]`.
```
Assertion failed: (it != m_data.m_value.object->end()), function operator[], file json.hpp, line 28795.
```
??? example "Example 2: Invalid array index in a JSON pointer" ??? example "Example 2: Invalid array index in a JSON pointer"
@@ -69,11 +69,7 @@ See also the documentation on [element access](element_access/index.md).
} }
``` ```
Output: The assertion `#!cpp idx < ptr->m_data.m_value.array->size()` fails in `#!cpp get_unchecked`.
```
Assertion failed: (idx < m_data.m_value.array->size()), function operator[], file json.hpp, line 28758.
```
### Constructing from an uninitialized iterator range ### Constructing from an uninitialized iterator range
@@ -96,11 +92,7 @@ uninitialized iterator is undefined behavior and yields a runtime assertion.
} }
``` ```
Output: The assertion `#!cpp first.m_object != nullptr` fails in `#!cpp basic_json`.
```
Assertion failed: (m_object != nullptr), function operator++, file iter_impl.hpp, line 368.
```
### Operations on uninitialized iterators ### Operations on uninitialized iterators
@@ -123,11 +115,7 @@ behavior and yields a runtime assertion.
} }
``` ```
Output: The assertion `#!cpp m_object != nullptr` fails in `#!cpp operator++`.
```
Assertion failed: (m_object != nullptr), function operator++, file iter_impl.hpp, line 368.
```
## Changes ## Changes