Can Parse Pair To Template Has 2 Typename
Types¶
This page gives an overview how JSON values are stored and how this can exist configured.
Overview¶
By default, JSON values are stored as follows:
| JSON type | C++ blazon |
|---|---|
| object | std::map<std::string, basic_json> |
| array | std::vector<basic_json> |
| null | std::nullptr_t |
| cord | std::string |
| boolean | bool |
| number | std::int64_t, std::uint64_t, and double |
Note at that place are 3 different types for numbers - when parsing JSON text, the best fitting type is chosen.
Storage¶
Template arguments¶
The data types to store a JSON value are derived from the template arguments passed to class basic_json:
template < template < typename U , typename Five , typename ... Args > class ObjectType = std :: map , template < typename U , typename ... Args > class ArrayType = std :: vector , class StringType = std :: cord , class BooleanType = bool , class NumberIntegerType = std :: int64_t , grade NumberUnsignedType = std :: uint64_t , form NumberFloatType = double , template < typename U > class AllocatorType = std :: allocator , template < typename T , typename SFINAE = void > class JSONSerializer = adl_serializer , class BinaryType = std :: vector < std :: uint8_t > > class basic_json ; Type json is an allonym for basic_json<> and uses the default types.
From the template arguments, the following types are derived:
using object_comparator_t = std :: less <> ; using object_t = ObjectType < StringType , basic_json , object_comparator_t , AllocatorType < std :: pair < const StringType , basic_json >>> ; using array_t = ArrayType < basic_json , AllocatorType < basic_json >> ; using string_t = StringType ; using boolean_t = BooleanType ; using number_integer_t = NumberIntegerType ; using number_unsigned_t = NumberUnsignedType ; using number_float_t = NumberFloatType ; using binary_t = nlohmann :: byte_container_with_subtype < BinaryType > ; Objects¶
RFC 8259 describes JSON objects every bit follows:
An object is an unordered drove of nil or more name/value pairs, where a name is a cord and a value is a string, number, boolean, null, object, or array.
Default type¶
With the default values for ObjectType (std::map), StringType (std::string), and AllocatorType (std::allocator), the default value for object_t is:
std :: map < std :: string , // key_type basic_json , // value_type std :: less <> , // key_compare std :: allocator < std :: pair < const std :: cord , basic_json >> // allocator_type > Behavior¶
The choice of object_t influences the behavior of the JSON class. With the default type, objects have the following beliefs:
- When all names are unique, objects volition be interoperable in the sense that all software implementations receiving that object will agree on the proper noun-value mappings.
- When the names inside an object are not unique, it is unspecified which one of the values for a given key volition be chosen. For instance,
{ "key" : ii , "key" : 1 }could be equal to either{ "key" : 1 }or{ "key" : 2 }. - Internally, proper name/value pairs are stored in lexicographical order of the names. Objects will too be serialized (encounter
dump) in this social club. For example, both{ "b" : one , "a" : two }and{ "a" : 2 , "b" : 1 }will be stored and serialized as{ "a" : 2 , "b" : 1 }. - When comparison objects, the society of the proper noun/value pairs is irrelevant. This makes objects interoperable in the sense that they will not be affected by these differences. For example,
{ "b" : ane , "a" : two }and{ "a" : 2 , "b" : ane }volition be treated as equal.
Key social club¶
The order name/value pairs are added to the object is non preserved by the library. Therefore, iterating an object may return name/value pairs in a different order than they were originally stored. In fact, keys will be traversed in alphabetical social club every bit std::map with std::less is used by default. Please note this behavior conforms to RFC 8259, considering whatever order implements the specified "unordered" nature of JSON objects.
Limits¶
RFC 8259 specifies:
An implementation may set limits on the maximum depth of nesting.
In this form, the object'southward limit of nesting is non explicitly constrained. Still, a maximum depth of nesting may exist introduced by the compiler or runtime environment. A theoretical limit tin can be queried by calling the max_size function of a JSON object.
Storage¶
Objects are stored as pointers in a basic_json type. That is, for whatever access to object values, a pointer of type object_t* must exist dereferenced.
Arrays¶
RFC 8259 describes JSON arrays equally follows:
An array is an ordered sequence of zero or more values.
Default blazon¶
With the default values for ArrayType (std::vector) and AllocatorType (std::allocator), the default value for array_t is:
std :: vector < basic_json , // value_type std :: allocator < basic_json > // allocator_type > Limits¶
RFC 8259 specifies:
An implementation may fix limits on the maximum depth of nesting.
In this form, the array's limit of nesting is not explicitly constrained. However, a maximum depth of nesting may be introduced by the compiler or runtime environment. A theoretical limit tin be queried by calling the max_size office of a JSON array.
Storage¶
Arrays are stored as pointers in a basic_json type. That is, for any admission to array values, a arrow of type array_t* must be dereferenced.
Strings¶
RFC 8259 describes JSON strings as follows:
A cord is a sequence of nothing or more Unicode characters.
Unicode values are dissever by the JSON class into byte-sized characters during deserialization.
Default type¶
With the default values for StringType (std::string), the default value for string_t is std :: string .
Encoding¶
Strings are stored in UTF-8 encoding. Therefore, functions like std::cord::size() or std::string::length() return the number of bytes in the string rather than the number of characters or glyphs.
String comparison¶
RFC 8259 states:
Software implementations are typically required to test names of object members for equality. Implementations that transform the textual representation into sequences of Unicode code units and then perform the comparison numerically, code unit by code unit of measurement, are interoperable in the sense that implementations volition agree in all cases on equality or inequality of 2 strings. For example, implementations that compare strings with escaped characters unconverted may incorrectly find that
"a\\b"and"a\u005Cb"are not equal.
This implementation is interoperable as it does compare strings code unit of measurement by code unit of measurement.
Storage¶
Cord values are stored as pointers in a basic_json type. That is, for any access to string values, a arrow of type string_t* must be dereferenced.
Booleans¶
RFC 8259 implicitly describes a boolean as a blazon which differentiates the two literals true and imitation.
Default type¶
With the default values for BooleanType ( bool ), the default value for boolean_t is bool .
Storage¶
Boolean values are stored directly inside a basic_json type.
Numbers¶
Run into the number handling article for a detailed word on how numbers are handled by this library.
RFC 8259 describes numbers as follows:
The representation of numbers is like to that used in most programming languages. A number is represented in base 10 using decimal digits. It contains an integer component that may be prefixed with an optional minus sign, which may be followed past a fraction part and/or an exponent part. Leading zeros are non allowed. (...) Numeric values that cannot exist represented in the grammer below (such equally Infinity and NaN) are not permitted.
This description includes both integer and floating-point numbers. Nonetheless, C++ allows more precise storage if information technology is known whether the number is a signed integer, an unsigned integer or a floating-indicate number. Therefore, three dissimilar types, number_integer_t, number_unsigned_t, and number_float_t are used.
Default types¶
With the default values for NumberIntegerType (std::int64_t), the default value for number_integer_t is std::int64_t. With the default values for NumberUnsignedType (std::uint64_t), the default value for number_unsigned_t is std::uint64_t. With the default values for NumberFloatType ( double ), the default value for number_float_t is double .
Default beliefs¶
- The restrictions about leading zeros is not enforced in C++. Instead, leading zeros in integer literals lead to an interpretation as octal number. Internally, the value will be stored every bit decimal number. For case, the C++ integer literal
010will be serialized toviii. During deserialization, leading zeros yield an error. - Not-a-number (NaN) values will be serialized to
null.
Limits¶
RFC 8259 specifies:
An implementation may set limits on the range and precision of numbers.
When the default type is used, the maximal integer number that tin be stored is 9223372036854775807 (INT64_MAX) and the minimal integer number that tin can be stored is -9223372036854775808 (INT64_MIN). Integer numbers that are out of range volition yield over/underflow when used in a constructor. During deserialization, also big or small integer numbers will be automatically be stored equally number_unsigned_t or number_float_t.
When the default type is used, the maximal unsigned integer number that can be stored is 18446744073709551615 (UINT64_MAX) and the minimal integer number that tin can be stored is 0 . Integer numbers that are out of range will yield over/underflow when used in a constructor. During deserialization, as well large or small integer numbers will exist automatically be stored as number_integer_t or number_float_t.
RFC 8259 further states:
Note that when such software is used, numbers that are integers and are in the range [-2^{53}+1, ii^{53}-i] are interoperable in the sense that implementations will hold exactly on their numeric values.
As this range is a subrange of the exactly supported range [INT64_MIN, INT64_MAX], this form's integer blazon is interoperable.
RFC 8259 states:
This specification allows implementations to prepare limits on the range and precision of numbers accepted. Since software that implements IEEE 754-2008 binary64 (double precision) numbers is by and large available and widely used, skilful interoperability can be achieved by implementations that look no more precision or range than these provide, in the sense that implementations volition approximate JSON numbers within the expected precision.
This implementation does exactly follow this approach, as it uses double precision floating-bespeak numbers. Annotation values smaller than -1.79769313486232e+308 and values greater than 1.79769313486232e+308 will be stored as NaN internally and exist serialized to null .
Storage¶
Integer number values, unsigned integer number values, and floating-point number values are stored directly inside a basic_json type.
Can Parse Pair To Template Has 2 Typename,
Source: https://json.nlohmann.me/features/types/
Posted by: frazieryounly.blogspot.com

0 Response to "Can Parse Pair To Template Has 2 Typename"
Post a Comment