|
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<class InputIT , typename std::enable_if< std::is_same< InputIT, typename __basic_json::iterator >::value orstd::is_same< InputIT, typename __basic_json::const_iterator >::value, int >::type = 0>
Constructs the JSON value with the contents of the range [first, last) . The semantics depends on the different types a JSON value can have:
- In case of primitive types (number, boolean, or string), first must be
begin() and last must be end() . In this case, the value is copied. Otherwise, std::out_of_range is thrown.
- In case of structured types (array, object), the constructor behaves as similar versions for
std::vector .
- In case of a null type, std::domain_error is thrown.
- Template Parameters
-
- Parameters
-
[in] | first | begin of the range to copy from (included) |
[in] | last | end of the range to copy from (excluded) |
- Exceptions
-
std::domain_error | if iterators are not compatible; that is, do not belong to the same JSON value |
std::out_of_range | if iterators are for a primitive type (number, boolean, or string) where an out of range error can be detected easily |
std::bad_alloc | if allocation for object, array, or string fails |
std::domain_error | if called with a null value |
- Complexity
- Linear in distance between first and last.
- Example
- The example below shows several ways to create JSON values by specifying a subrange with iterators.
8 json j_array = { "alpha", "bravo", "charly", "delta", "easy"};
10 json j_object = {{ "one", "eins"}, { "two", "zwei"}};
13 json j_array_range(j_array. begin() + 1, j_array. end() - 2);
18 std::cout << j_array_range << '\n';
19 std::cout << j_number_range << '\n';
20 std::cout << j_object_range << '\n';
a class to store JSON values Definition: json.hpp:130
iterator end() returns an iterator to one past the last element Definition: json.hpp:3190
iterator begin() returns an iterator to the first element Definition: json.hpp:3130
iterator find(typename object_t::key_type key) find an element in a JSON object Definition: json.hpp:3052
namespace for Niels Lohmann Definition: json.hpp:55
Output (play with this example online): ["bravo","charly"]
42
{"one":"eins"}
The example code above can be translated withg++ -std=c++11 -Isrc doc/examples/basic_json__InputIt_InputIt.cpp -o basic_json__InputIt_InputIt
|