diff --git a/api/basic_json/at.md b/api/basic_json/at.md index 45ec2b27d..58d9ceb28 100644 --- a/api/basic_json/at.md +++ b/api/basic_json/at.md @@ -90,7 +90,8 @@ Strong exception safety: if an exception occurs, the original value stays intact 1. Constant. 2. Logarithmic in the size of the container. 3. Logarithmic in the size of the container. -4. Logarithmic in the size of the container. +4. Linear in the number of reference tokens of `ptr`; for each of them, logarithmic in the size of the object, or + constant for an array. ## Notes diff --git a/api/basic_json/at/index.html b/api/basic_json/at/index.html index cfd19383e..ec0bd176b 100644 --- a/api/basic_json/at/index.html +++ b/api/basic_json/at/index.html @@ -15,7 +15,7 @@ // (4) reference at(const json_pointer& ptr); const_reference at(const json_pointer& ptr) const; -
idx, with bounds checking.key, with bounds checking.KeyType is comparable with typename object_t::key_type and typename object_comparator_t::is_transparent denotes a type.ptr, with bounds checking.KeyTypejson_pointer that is comparable with string_t using object_comparator_t. This can also be a string view (C++17).idx (in)key (in)ptr (in)idxkeykeyptrStrong exception safety: if an exception occurs, the original value stays intact.
type_error.304 if the JSON value is not an array; in this case, calling at with an index makes no sense. See the example below.out_of_range.401 if the index idx is out of range of the array; that is, idx >= size(). See the example below.type_error.304 if the JSON value is not an object; in this case, calling at with a key makes no sense. See the example below.out_of_range.403 if the key key is not stored in the object; that is, find(key) == end(). See the example below.parse_error.106 if an array index in the passed JSON pointer ptr begins with '0'. See the example below.parse_error.109 if an array index in the passed JSON pointer ptr is not a number. See the example below.out_of_range.401 if an array index in the passed JSON pointer ptr is out of range. See the example below.out_of_range.402 if the array index '-' is used in the passed JSON pointer ptr. As at provides checked access (and no elements are implicitly inserted), the index '-' is always invalid. See the example below.out_of_range.403 if the JSON pointer describes a key of an object which cannot be found. See the example below.out_of_range.404 if the JSON pointer ptr can not be resolved. See the example below.out_of_range.410 if an array index in the passed JSON pointer ptr exceeds the range of size_type (e.g., on 32-bit platforms).Deprecation
Overload (4) also accepts a json_pointer whose template argument is a basic_json specialization (e.g., nlohmann::json_pointer<nlohmann::json>) instead of a string type. This is deprecated since version 3.11.0 and will be removed in a future major version; use basic_json::json_pointer (for json, nlohmann::json_pointer<std::string>) instead.
You should be warned by your compiler with a -Wdeprecated-declarations warning if you are using a deprecated function.
See the migration guide for how to update existing code.
The example below shows how array elements can be read and written using at(). It also demonstrates the different exceptions that can be thrown.
#include <iostream>
+idx, with bounds checking.key, with bounds checking.KeyType is comparable with typename object_t::key_type and typename object_comparator_t::is_transparent denotes a type.ptr, with bounds checking.KeyTypejson_pointer that is comparable with string_t using object_comparator_t. This can also be a string view (C++17).idx (in)key (in)ptr (in)idxkeykeyptrStrong exception safety: if an exception occurs, the original value stays intact.
type_error.304 if the JSON value is not an array; in this case, calling at with an index makes no sense. See the example below.out_of_range.401 if the index idx is out of range of the array; that is, idx >= size(). See the example below.type_error.304 if the JSON value is not an object; in this case, calling at with a key makes no sense. See the example below.out_of_range.403 if the key key is not stored in the object; that is, find(key) == end(). See the example below.parse_error.106 if an array index in the passed JSON pointer ptr begins with '0'. See the example below.parse_error.109 if an array index in the passed JSON pointer ptr is not a number. See the example below.out_of_range.401 if an array index in the passed JSON pointer ptr is out of range. See the example below.out_of_range.402 if the array index '-' is used in the passed JSON pointer ptr. As at provides checked access (and no elements are implicitly inserted), the index '-' is always invalid. See the example below.out_of_range.403 if the JSON pointer describes a key of an object which cannot be found. See the example below.out_of_range.404 if the JSON pointer ptr can not be resolved. See the example below.out_of_range.410 if an array index in the passed JSON pointer ptr exceeds the range of size_type (e.g., on 32-bit platforms).ptr; for each of them, logarithmic in the size of the object, or constant for an array.Deprecation
Overload (4) also accepts a json_pointer whose template argument is a basic_json specialization (e.g., nlohmann::json_pointer<nlohmann::json>) instead of a string type. This is deprecated since version 3.11.0 and will be removed in a future major version; use basic_json::json_pointer (for json, nlohmann::json_pointer<std::string>) instead.
You should be warned by your compiler with a -Wdeprecated-declarations warning if you are using a deprecated function.
See the migration guide for how to update existing code.
The example below shows how array elements can be read and written using at(). It also demonstrates the different exceptions that can be thrown.
#include <iostream>
#include <nlohmann/json.hpp>
using nlohmann::json;
@@ -498,4 +498,4 @@
[json.exception.out_of_range.402] array index '-' (2) is out of range
[json.exception.out_of_range.403] key 'foo' not found
[json.exception.out_of_range.404] unresolved reference token 'foo'
-operator[] - unchecked access by referencevalue - access with default valuebasic_json_view::at - the same access on a zero-copy viewstd::string_view added in version 3.13.0 unreleased, consistently across the lookup functions.parse_error.109 instead of out_of_range.404 for a one-character array index that is not a digit (e.g., /x) in version 3.13.0 unreleased, as it already did for longer ones.