Files
json/docs/mkdocs/docs/api/basic_json_view/end.md
T
Niels Lohmann 0660e6d482 Address the second review round of json_view element access
From gregmarr's review of #5622:

- begin()/end(): "a null value or a discarded view iterates as an empty
  range", singular like the primitive case before it.
- The class page's list of function groups has no trailing commas.
- document_data::key_equals() compares a key node with a string, for the
  key comparisons that were spelled out in each lookup.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-18 22:20:57 +02:00

1.5 KiB

nlohmann::basic_json_view::end

iterator end() const noexcept;

Returns an iterator to one past the last element of an array, one past the last member value of an object, in document order -- see begin(). A primitive value iterates as a range of one element (itself), and a #!json null value or a discarded view iterates as an empty range (#!cpp begin() == end()).

Return value

Iterator one past the last element.

Exception safety

No-throw guarantee: this function never throws exceptions.

Complexity

Constant.

Notes

#!cpp iterator is a forward iterator: unlike BasicJsonType::iterator, it cannot be decremented, so there is no way to reach the last element by stepping back from end(). Use back() instead.

Examples

??? example

The example below scans a (possibly large) array of readings for the first one over a threshold, stopping the
loop at `end()` as soon as one is found. Only the matching reading, if any, is ever materialized.

```cpp
--8<-- "examples/basic_json_view__end.cpp"
```

Output:

```json
--8<-- "examples/basic_json_view__end.output"
```

See also

  • begin - returns an iterator to the first element
  • cend - returns a const iterator to one past the last element
  • BasicJsonType::end - the corresponding function of basic_json

Version history

  • Added in version 3.13.0.