From e050105fc85022765558634b42c8961893837e6b Mon Sep 17 00:00:00 2001 From: Niels Date: Sun, 12 Apr 2015 15:38:22 +0200 Subject: [PATCH] Created nlohmann::basicjson::at (markdown) --- nlohmann::basicjson::at.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 nlohmann::basicjson::at.md diff --git a/nlohmann::basicjson::at.md b/nlohmann::basicjson::at.md new file mode 100644 index 0000000..3ded448 --- /dev/null +++ b/nlohmann::basicjson::at.md @@ -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.