improved documentation for #289
This commit is contained in:
parent
37fdcd893d
commit
03de590372
3 changed files with 29 additions and 11 deletions
|
@ -498,7 +498,7 @@ Thanks a lot for helping out!
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
- The code contains numerous debug **assertions** which can be switched off by defining the preprocessor macro `NDEBUG`, see the [documentation of `assert`](http://en.cppreference.com/w/cpp/error/assert).
|
- The code contains numerous debug **assertions** which can be switched off by defining the preprocessor macro `NDEBUG`, see the [documentation of `assert`](http://en.cppreference.com/w/cpp/error/assert). In particular, note [`operator[]`](https://nlohmann.github.io/json/classnlohmann_1_1basic__json_a2e26bd0b0168abb61f67ad5bcd5b9fa1.html#a2e26bd0b0168abb61f67ad5bcd5b9fa1) implements **unchecked access** for const objects: If the given key is not present, the behavior is undefined (think of a dereferenced null pointer) and yields an [assertion failure](https://github.com/nlohmann/json/issues/289) if assertions are switched on. If you are not sure whether an element in an object exists, use checked access with the [`at()` function](https://nlohmann.github.io/json/classnlohmann_1_1basic__json_a674de1ee73e6bf4843fc5dc1351fb726.html#a674de1ee73e6bf4843fc5dc1351fb726).
|
||||||
- As the exact type of a number is not defined in the [JSON specification](http://rfc7159.net/rfc7159), this library tries to choose the best fitting C++ number type automatically. As a result, the type `double` may be used to store numbers which may yield [**floating-point exceptions**](https://github.com/nlohmann/json/issues/181) in certain rare situations if floating-point exceptions have been unmasked in the calling code. These exceptions are not caused by the library and need to be fixed in the calling code, such as by re-masking the exceptions prior to calling library functions.
|
- As the exact type of a number is not defined in the [JSON specification](http://rfc7159.net/rfc7159), this library tries to choose the best fitting C++ number type automatically. As a result, the type `double` may be used to store numbers which may yield [**floating-point exceptions**](https://github.com/nlohmann/json/issues/181) in certain rare situations if floating-point exceptions have been unmasked in the calling code. These exceptions are not caused by the library and need to be fixed in the calling code, such as by re-masking the exceptions prior to calling library functions.
|
||||||
|
|
||||||
|
|
||||||
|
|
19
src/json.hpp
19
src/json.hpp
|
@ -1843,7 +1843,8 @@ class basic_json
|
||||||
@param[in] first begin of the range to copy from (included)
|
@param[in] first begin of the range to copy from (included)
|
||||||
@param[in] last end of the range to copy from (excluded)
|
@param[in] last end of the range to copy from (excluded)
|
||||||
|
|
||||||
@pre Iterators @a first and @a last must be initialized.
|
@pre Iterators @a first and @a last must be initialized. **This
|
||||||
|
precondition is enforced with an assertion.**
|
||||||
|
|
||||||
@throw std::domain_error if iterators are not compatible; that is, do not
|
@throw std::domain_error if iterators are not compatible; that is, do not
|
||||||
belong to the same JSON value; example: `"iterators are not compatible"`
|
belong to the same JSON value; example: `"iterators are not compatible"`
|
||||||
|
@ -3509,6 +3510,9 @@ class basic_json
|
||||||
|
|
||||||
@return const reference to the element at key @a key
|
@return const reference to the element at key @a key
|
||||||
|
|
||||||
|
@pre The element with key @a key must exist. **This precondition is
|
||||||
|
enforced with an assertion.**
|
||||||
|
|
||||||
@throw std::domain_error if JSON is not an object; example: `"cannot use
|
@throw std::domain_error if JSON is not an object; example: `"cannot use
|
||||||
operator[] with null"`
|
operator[] with null"`
|
||||||
|
|
||||||
|
@ -3667,6 +3671,9 @@ class basic_json
|
||||||
|
|
||||||
@return const reference to the element at key @a key
|
@return const reference to the element at key @a key
|
||||||
|
|
||||||
|
@pre The element with key @a key must exist. **This precondition is
|
||||||
|
enforced with an assertion.**
|
||||||
|
|
||||||
@throw std::domain_error if JSON is not an object; example: `"cannot use
|
@throw std::domain_error if JSON is not an object; example: `"cannot use
|
||||||
operator[] with null"`
|
operator[] with null"`
|
||||||
|
|
||||||
|
@ -3867,7 +3874,8 @@ class basic_json
|
||||||
@complexity Constant.
|
@complexity Constant.
|
||||||
|
|
||||||
@pre The JSON value must not be `null` (would throw `std::out_of_range`)
|
@pre The JSON value must not be `null` (would throw `std::out_of_range`)
|
||||||
or an empty array or object (undefined behavior, guarded by assertions).
|
or an empty array or object (undefined behavior, **guarded by
|
||||||
|
assertions**).
|
||||||
@post The JSON value remains unchanged.
|
@post The JSON value remains unchanged.
|
||||||
|
|
||||||
@throw std::out_of_range when called on `null` value
|
@throw std::out_of_range when called on `null` value
|
||||||
|
@ -3909,7 +3917,8 @@ class basic_json
|
||||||
@complexity Constant.
|
@complexity Constant.
|
||||||
|
|
||||||
@pre The JSON value must not be `null` (would throw `std::out_of_range`)
|
@pre The JSON value must not be `null` (would throw `std::out_of_range`)
|
||||||
or an empty array or object (undefined behavior, guarded by assertions).
|
or an empty array or object (undefined behavior, **guarded by
|
||||||
|
assertions**).
|
||||||
@post The JSON value remains unchanged.
|
@post The JSON value remains unchanged.
|
||||||
|
|
||||||
@throw std::out_of_range when called on `null` value.
|
@throw std::out_of_range when called on `null` value.
|
||||||
|
@ -6592,8 +6601,8 @@ class basic_json
|
||||||
@note An iterator is called *initialized* when a pointer to a JSON value
|
@note An iterator is called *initialized* when a pointer to a JSON value
|
||||||
has been set (e.g., by a constructor or a copy assignment). If the
|
has been set (e.g., by a constructor or a copy assignment). If the
|
||||||
iterator is default-constructed, it is *uninitialized* and most
|
iterator is default-constructed, it is *uninitialized* and most
|
||||||
methods are undefined. The library uses assertions to detect calls
|
methods are undefined. **The library uses assertions to detect calls
|
||||||
on uninitialized iterators.
|
on uninitialized iterators.**
|
||||||
|
|
||||||
@requirement The class satisfies the following concept requirements:
|
@requirement The class satisfies the following concept requirements:
|
||||||
- [RandomAccessIterator](http://en.cppreference.com/w/cpp/concept/RandomAccessIterator):
|
- [RandomAccessIterator](http://en.cppreference.com/w/cpp/concept/RandomAccessIterator):
|
||||||
|
|
|
@ -1843,7 +1843,8 @@ class basic_json
|
||||||
@param[in] first begin of the range to copy from (included)
|
@param[in] first begin of the range to copy from (included)
|
||||||
@param[in] last end of the range to copy from (excluded)
|
@param[in] last end of the range to copy from (excluded)
|
||||||
|
|
||||||
@pre Iterators @a first and @a last must be initialized.
|
@pre Iterators @a first and @a last must be initialized. **This
|
||||||
|
precondition is enforced with an assertion.**
|
||||||
|
|
||||||
@throw std::domain_error if iterators are not compatible; that is, do not
|
@throw std::domain_error if iterators are not compatible; that is, do not
|
||||||
belong to the same JSON value; example: `"iterators are not compatible"`
|
belong to the same JSON value; example: `"iterators are not compatible"`
|
||||||
|
@ -3509,6 +3510,9 @@ class basic_json
|
||||||
|
|
||||||
@return const reference to the element at key @a key
|
@return const reference to the element at key @a key
|
||||||
|
|
||||||
|
@pre The element with key @a key must exist. **This precondition is
|
||||||
|
enforced with an assertion.**
|
||||||
|
|
||||||
@throw std::domain_error if JSON is not an object; example: `"cannot use
|
@throw std::domain_error if JSON is not an object; example: `"cannot use
|
||||||
operator[] with null"`
|
operator[] with null"`
|
||||||
|
|
||||||
|
@ -3667,6 +3671,9 @@ class basic_json
|
||||||
|
|
||||||
@return const reference to the element at key @a key
|
@return const reference to the element at key @a key
|
||||||
|
|
||||||
|
@pre The element with key @a key must exist. **This precondition is
|
||||||
|
enforced with an assertion.**
|
||||||
|
|
||||||
@throw std::domain_error if JSON is not an object; example: `"cannot use
|
@throw std::domain_error if JSON is not an object; example: `"cannot use
|
||||||
operator[] with null"`
|
operator[] with null"`
|
||||||
|
|
||||||
|
@ -3867,7 +3874,8 @@ class basic_json
|
||||||
@complexity Constant.
|
@complexity Constant.
|
||||||
|
|
||||||
@pre The JSON value must not be `null` (would throw `std::out_of_range`)
|
@pre The JSON value must not be `null` (would throw `std::out_of_range`)
|
||||||
or an empty array or object (undefined behavior, guarded by assertions).
|
or an empty array or object (undefined behavior, **guarded by
|
||||||
|
assertions**).
|
||||||
@post The JSON value remains unchanged.
|
@post The JSON value remains unchanged.
|
||||||
|
|
||||||
@throw std::out_of_range when called on `null` value
|
@throw std::out_of_range when called on `null` value
|
||||||
|
@ -3909,7 +3917,8 @@ class basic_json
|
||||||
@complexity Constant.
|
@complexity Constant.
|
||||||
|
|
||||||
@pre The JSON value must not be `null` (would throw `std::out_of_range`)
|
@pre The JSON value must not be `null` (would throw `std::out_of_range`)
|
||||||
or an empty array or object (undefined behavior, guarded by assertions).
|
or an empty array or object (undefined behavior, **guarded by
|
||||||
|
assertions**).
|
||||||
@post The JSON value remains unchanged.
|
@post The JSON value remains unchanged.
|
||||||
|
|
||||||
@throw std::out_of_range when called on `null` value.
|
@throw std::out_of_range when called on `null` value.
|
||||||
|
@ -6592,8 +6601,8 @@ class basic_json
|
||||||
@note An iterator is called *initialized* when a pointer to a JSON value
|
@note An iterator is called *initialized* when a pointer to a JSON value
|
||||||
has been set (e.g., by a constructor or a copy assignment). If the
|
has been set (e.g., by a constructor or a copy assignment). If the
|
||||||
iterator is default-constructed, it is *uninitialized* and most
|
iterator is default-constructed, it is *uninitialized* and most
|
||||||
methods are undefined. The library uses assertions to detect calls
|
methods are undefined. **The library uses assertions to detect calls
|
||||||
on uninitialized iterators.
|
on uninitialized iterators.**
|
||||||
|
|
||||||
@requirement The class satisfies the following concept requirements:
|
@requirement The class satisfies the following concept requirements:
|
||||||
- [RandomAccessIterator](http://en.cppreference.com/w/cpp/concept/RandomAccessIterator):
|
- [RandomAccessIterator](http://en.cppreference.com/w/cpp/concept/RandomAccessIterator):
|
||||||
|
|
Loading…
Reference in a new issue