Created nlohmann::basicjson::size (markdown)
1 parent
8e9a0243ea
commit
cb90714cd1
1 file changed
+54
@@ -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 <iostream>
|
||||
#include <json.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
nlohmann::json values {"string", true, 17, 23.42};
|
||||
|
||||
std::cout << "values contains " << values.size() << " elements.\n";
|
||||
}
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```
|
||||
values contains 4 elements.
|
||||
```
|
||||
Reference in new issue
Block a user