Created nlohmann::basicjson::max_size (markdown)

Niels committed 2015-04-11 16:54:03 +02:00
1 parent 092c96134a
commit 9408ae5caf
1 file changed
+62
+62
@@ -0,0 +1,62 @@
```cpp
size_type max_size() const;
```
## Description
Returns the type-dependent maximum number of elements the JSON container is able to hold due to system or library implementation limitations, i.e. `std::distance(begin(), end())` for the largest container.
## 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::max_size()` |
| array | `ArrayType::max_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`.
## Notes
This value is typically equal to `std::numeric_limits<size_type>::max()`, and reflects the theoretical limit on the size of the container. At runtime, the size of the container may be limited to a value smaller than `max_size()` by the amount of RAM available.
## Example
```cpp
#include <iostream>
#include <json.hpp>
int main()
{
nlohmann::json array {"string", true, 17, 23.42};
std::cout << "Maximum size of a JSON array is " << array.max_size() << "\n";
}
```
Output:
```
Maximum size of a JSON array is 1152921504606846975
```
## See also
- [**size**](https://github.com/nlohmann/json/wiki/nlohmann::basicjson::size)<br>
returns the number of elements<br>
_public member function_