Created nlohmann::basicjson::at (markdown)

Niels committed 2015-04-12 15:38:22 +02:00
1 parent 86e24d873f
commit e050105fc8
1 file changed
+32
+32
@@ -0,0 +1,32 @@
```cpp
reference at(size_type idx);
const_reference at(size_type idx) const; // 1
```
```cpp
reference at(const object_t::key_type& key)
const_reference at(const object_t::key_type& key) const // 2
```
## Description
1. Returns a reference to the element at specified index `idx`, with bounds checking. If `idx` not within the range of the container, an exception of type `std::out_of_range` is thrown (only works for arrays).
2. Returns a reference to the mapped value of the element with key equivalent to `key`. If no such element exists, an exception of type `std::out_of_range` is thrown (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`; `std::out_of_range` if `!(idx < size())`.
2. `std::runtime_error` when called on a JSON container with other type than `object`; `std::out_of_range` if the container does not have an element with the specified key.