From e79f539583934c7135918fa281f6975a586e3f1e Mon Sep 17 00:00:00 2001 From: Niels Date: Sun, 12 Apr 2015 15:52:24 +0200 Subject: [PATCH] Created nlohmann::basicjson::operator[] (markdown) --- nlohmann::basicjson::operator[].md | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 nlohmann::basicjson::operator[].md diff --git a/nlohmann::basicjson::operator[].md b/nlohmann::basicjson::operator[].md new file mode 100644 index 0000000..5b9cd3e --- /dev/null +++ b/nlohmann::basicjson::operator[].md @@ -0,0 +1,34 @@ +```cpp +reference operator[](size_type idx); // 1 +const_reference operator[](size_type idx) const; // 2 +``` +```cpp +reference operator[](const object_t::key_type& key) // 3 +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). +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). +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 + +- `idx`: index of the element to return +- `key`: key of the element to return + +## Return value + +Reference to the specified value. + +## Complexity + +1. Constant. +2. 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`.