From 4ceb25bcda62331fcdd5806663c5d8a13399579e Mon Sep 17 00:00:00 2001 From: Niels Date: Sun, 12 Apr 2015 16:03:23 +0200 Subject: [PATCH] Updated nlohmann::basicjson::operator[] (markdown) --- nlohmann::basicjson::operator[].md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/nlohmann::basicjson::operator[].md b/nlohmann::basicjson::operator[].md index 5b9cd3e..3ce8c20 100644 --- a/nlohmann::basicjson::operator[].md +++ b/nlohmann::basicjson::operator[].md @@ -9,9 +9,9 @@ const_reference operator[](const object_t::key_type& key) const // 4 ## Description -1. Returns a reference to the element at specified index `idx`. No bounds checking is performed. In case `idx > size()`, null values are inserted between `size()` and `idx - 1` (only works for arrays). +1. Returns a reference to the element at specified index `idx`. In case `idx > size()`, null values are inserted between `size()` and `idx` before (only works for arrays). 2. Returns a reference to the element at specified index `idx`. No bounds checking is performed and no values will be inserted (only works for arrays). -3. Returns a reference to the value that is mapped to a key equivalent to `key`, performing an insertion if such key does not already exist. If an insertion is performed, the mapped value is value-initialized (default-constructed for class types, zero-initialized otherwise) and a reference to it is returned. No bounds checking is performed (only works for objects). +3. Returns a reference to the value that is mapped to a key equivalent to `key`, performing an insertion of a null value if such key does not already exist and returns a reference to this value (only works for objects). 4. Returns a reference to the mapped value of the element with key equivalent to `key`. No bounds checking is performed and no values will be inserted (only works for objects). ## Parameters @@ -21,14 +21,16 @@ const_reference operator[](const object_t::key_type& key) const // 4 ## Return value -Reference to the specified value. +Reference to the specified value. In case of 1 and 3, the reference may be to a newly inserted null value. ## Complexity -1. Constant. -2. Logarithmic in the size of the container. +1. Linear in the distance between `size()` and `idx` if `idx > size()`, constant otherwise. +2. Constant. +3. Logarithmic in the size of the container. +4. Logarithmic in the size of the container. ## Exceptions 1. `std::runtime_error` when called on a JSON container with other type than `array`. -2. `std::runtime_error` when called on a JSON container with other type than `object`. +2. `std::runtime_error` when called on a JSON container with other type than `object`. \ No newline at end of file