- Make the iterator range illustrations legible in dark mode (prefers-color-scheme rules inside the SVGs). - Add a "Byte layout" section with a color-coded byte table to each binary format page (BJData, BON8, BSON, CBOR, MessagePack, UBJSON), and highlight the smallest size per file in the comparison table. - Add "See also" sections to the overview pages that lacked one. - Split the release notes into one page per release, grouped by minor version on the overview page, with an "API changes" section per release generated from the API pages' version histories (hooks/api_changes.py). - Fact-check the release notes and version histories against the release tags and correct wrong or misleading entries (e.g., json_serializer 2.1.0, merge_patch 3.1.0, items, count, operator[], to_bjdata, std::string_view key support). Signed-off-by: Niels Lohmann <mail@nlohmann.me>
67 lines
1.4 KiB
Markdown
67 lines
1.4 KiB
Markdown
# <small>nlohmann::basic_json::</small>back
|
|
|
|
```cpp
|
|
reference back();
|
|
|
|
const_reference back() const;
|
|
```
|
|
|
|
Returns a reference to the last element in the container. For a JSON container `c`, the expression `c.back()` is
|
|
equivalent to
|
|
|
|
```cpp
|
|
auto tmp = c.end();
|
|
--tmp;
|
|
return *tmp;
|
|
```
|
|
|
|
## Return value
|
|
|
|
In the case of a structured type (array or object), a reference to the last element is returned. In the case of number,
|
|
string, boolean, or binary values, a reference to the value is returned.
|
|
|
|
## Exception safety
|
|
|
|
Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
|
|
|
|
## Exceptions
|
|
|
|
If the JSON value is `#!json null`, exception
|
|
[`invalid_iterator.214`](../../home/exceptions.md#jsonexceptioninvalid_iterator214) is thrown.
|
|
|
|
## Complexity
|
|
|
|
Constant.
|
|
|
|
## Notes
|
|
|
|
!!! info "Precondition"
|
|
|
|
The array or object must not be empty. Calling `back` on an empty array or object yields undefined behavior.
|
|
|
|
## Examples
|
|
|
|
??? example
|
|
|
|
The following code shows an example for `back()`.
|
|
|
|
```cpp
|
|
--8<-- "examples/back.cpp"
|
|
```
|
|
|
|
Output:
|
|
|
|
```json
|
|
--8<-- "examples/back.output"
|
|
```
|
|
|
|
## See also
|
|
|
|
- [front](front.md) to access the first element
|
|
- [basic_json_view::back](../basic_json_view/back.md) - the same access on a zero-copy view
|
|
|
|
## Version history
|
|
|
|
- Added in version 1.0.0.
|
|
- Binary values are supported since version 3.8.0.
|