From cb90714cd1032281b6ee41d05f8f7f9da25dfc00 Mon Sep 17 00:00:00 2001 From: Niels Date: Thu, 9 Apr 2015 18:22:10 +0200 Subject: [PATCH] Created nlohmann::basicjson::size (markdown) --- nlohmann::basicjson::size.md | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 nlohmann::basicjson::size.md diff --git a/nlohmann::basicjson::size.md b/nlohmann::basicjson::size.md new file mode 100644 index 0000000..46f1bc7 --- /dev/null +++ b/nlohmann::basicjson::size.md @@ -0,0 +1,54 @@ +```cpp +size_type size() const; +``` + +## Description + +Returns the number of elements of a JSON value, i.e. `std::distance(begin(), end())`. + +## Return value + +The return value depends on the different value types and is defined as follows: + +| Value type | return value | +| ---------- | -------------------- | +| null | `0` | +| boolean | `1` | +| string | `1` | +| number | `1` | +| object | `ObjectType::size()` | +| array | `ArrayType::size()` | + +## Parameter + +None. + +## Complexity + +Constant, as long as `ArrayType` and `ObjectType` satisfy the [Container concept](http://en.cppreference.com/w/cpp/concept/Container). + +## Exceptions + +None. The function's noexcept-specification is `noexcept`. + +## Example + +The following code uses empty to check if a `nlohmann::json` contains any elements: + +```cpp +#include +#include + +int main() +{ + nlohmann::json values {"string", true, 17, 23.42}; + + std::cout << "values contains " << values.size() << " elements.\n"; +} +``` + +Output: + +``` +values contains 4 elements. +``` \ No newline at end of file