mirror of
https://github.com/nlohmann/json.git
synced 2026-11-11 22:51:34 +00:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
73db3b5fdb | ||
|
|
81f81a2262 | ||
|
|
fc2f5ea474 | ||
|
|
aaf63cbff6 |
No files matched your search
@@ -60,6 +60,14 @@ Linear.
|
|||||||
2. Comparing a `NaN` with another `NaN`.
|
2. Comparing a `NaN` with another `NaN`.
|
||||||
3. Comparing a `NaN` and any other number.
|
3. Comparing a `NaN` and any other number.
|
||||||
|
|
||||||
|
For arrays and objects, the elements are compared in order. If the comparison reaches a `NaN` and a number (or
|
||||||
|
another `NaN`) before any other difference, the result depends on the language standard. Before C++20, the pair
|
||||||
|
counts as equivalent and the following elements (or the sizes) decide: for instance, `[NaN] < [1, NaN]` and
|
||||||
|
`[1] <= [NaN]` are `#!cpp true`. Since C++20, the whole comparison is unordered, and `<`, `<=`, `>`, and `>=` all
|
||||||
|
yield `#!cpp false`. Otherwise (for example `[1, NaN] < [2, NaN]`, or objects whose keys differ), the result is the
|
||||||
|
same for all language standards. The same program can therefore order such values differently when it is compiled
|
||||||
|
with a different language standard.
|
||||||
|
|
||||||
!!! note "Operator overload resolution"
|
!!! note "Operator overload resolution"
|
||||||
|
|
||||||
Since C++20 overload resolution will consider the _rewritten candidate_ generated from
|
Since C++20 overload resolution will consider the _rewritten candidate_ generated from
|
||||||
|
|||||||
@@ -60,6 +60,14 @@ Linear.
|
|||||||
2. Comparing a `NaN` with another `NaN`.
|
2. Comparing a `NaN` with another `NaN`.
|
||||||
3. Comparing a `NaN` and any other number.
|
3. Comparing a `NaN` and any other number.
|
||||||
|
|
||||||
|
For arrays and objects, the elements are compared in order. If the comparison reaches a `NaN` and a number (or
|
||||||
|
another `NaN`) before any other difference, the result depends on the language standard. Before C++20, the pair
|
||||||
|
counts as equivalent and the following elements (or the sizes) decide: for instance, `[NaN] < [1, NaN]` and
|
||||||
|
`[1] <= [NaN]` are `#!cpp true`. Since C++20, the whole comparison is unordered, and `<`, `<=`, `>`, and `>=` all
|
||||||
|
yield `#!cpp false`. Otherwise (for example `[1, NaN] < [2, NaN]`, or objects whose keys differ), the result is the
|
||||||
|
same for all language standards. The same program can therefore order such values differently when it is compiled
|
||||||
|
with a different language standard.
|
||||||
|
|
||||||
!!! note "Operator overload resolution"
|
!!! note "Operator overload resolution"
|
||||||
|
|
||||||
Since C++20 overload resolution will consider the _rewritten candidate_ generated from
|
Since C++20 overload resolution will consider the _rewritten candidate_ generated from
|
||||||
|
|||||||
@@ -61,6 +61,14 @@ Linear.
|
|||||||
2. Comparing a `NaN` with another `NaN`.
|
2. Comparing a `NaN` with another `NaN`.
|
||||||
3. Comparing a `NaN` and any other number.
|
3. Comparing a `NaN` and any other number.
|
||||||
|
|
||||||
|
For arrays and objects, the elements are compared in order. If the comparison reaches a `NaN` and a number (or
|
||||||
|
another `NaN`) before any other difference, the result depends on the language standard. Before C++20, the pair
|
||||||
|
counts as equivalent and the following elements (or the sizes) decide: for instance, `[NaN] < [1, NaN]` and
|
||||||
|
`[1] <= [NaN]` are `#!cpp true`. Since C++20, the whole comparison is unordered, and `<`, `<=`, `>`, and `>=` all
|
||||||
|
yield `#!cpp false`. Otherwise (for example `[1, NaN] < [2, NaN]`, or objects whose keys differ), the result is the
|
||||||
|
same for all language standards. The same program can therefore order such values differently when it is compiled
|
||||||
|
with a different language standard.
|
||||||
|
|
||||||
!!! note "Operator overload resolution"
|
!!! note "Operator overload resolution"
|
||||||
|
|
||||||
Since C++20 overload resolution will consider the _rewritten candidate_ generated from
|
Since C++20 overload resolution will consider the _rewritten candidate_ generated from
|
||||||
|
|||||||
@@ -71,6 +71,14 @@ Linear.
|
|||||||
2. Comparing a `NaN` with another `NaN`.
|
2. Comparing a `NaN` with another `NaN`.
|
||||||
3. Comparing a `NaN` and any other number.
|
3. Comparing a `NaN` and any other number.
|
||||||
|
|
||||||
|
For arrays and objects, the elements are compared in order. If the comparison reaches a `NaN` and a number (or
|
||||||
|
another `NaN`) before any other difference, the result depends on the language standard. Before C++20, the pair
|
||||||
|
counts as equivalent and the following elements (or the sizes) decide: for instance, `[NaN] < [1, NaN]` and
|
||||||
|
`[1] <= [NaN]` are `#!cpp true`. Since C++20, the whole comparison is unordered, and `<`, `<=`, `>`, and `>=` all
|
||||||
|
yield `#!cpp false`. Otherwise (for example `[1, NaN] < [2, NaN]`, or objects whose keys differ), the result is the
|
||||||
|
same for all language standards. The same program can therefore order such values differently when it is compiled
|
||||||
|
with a different language standard.
|
||||||
|
|
||||||
!!! note "Operator overload resolution"
|
!!! note "Operator overload resolution"
|
||||||
|
|
||||||
Since C++20 overload resolution will consider the _rewritten candidate_ generated from
|
Since C++20 overload resolution will consider the _rewritten candidate_ generated from
|
||||||
|
|||||||
@@ -55,6 +55,10 @@ Linear.
|
|||||||
1. Comparing a `NaN` with itself.
|
1. Comparing a `NaN` with itself.
|
||||||
2. Comparing a `NaN` with another `NaN`.
|
2. Comparing a `NaN` with another `NaN`.
|
||||||
3. Comparing a `NaN` and any other number.
|
3. Comparing a `NaN` and any other number.
|
||||||
|
- For arrays and objects, the elements are compared in order. If the comparison reaches a `NaN` and a number (or
|
||||||
|
another `NaN`) before any other difference, the result is `std::partial_ordering::unordered`. (Without C++20, the
|
||||||
|
comparison operators `<`, `<=`, `>`, and `>=` use the comparison of the containers, which treats such a pair as
|
||||||
|
equivalent; see [**operator<**](operator_lt.md).)
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
|||||||
@@ -130,11 +130,13 @@ outside of a string, invalid) byte; see the [FAQ entry](../../home/faq.md#nul-by
|
|||||||
|
|
||||||
Contiguous inputs (strings, string views, vectors, arrays, pointer ranges) are the fastest to parse. A
|
Contiguous inputs (strings, string views, vectors, arrays, pointer ranges) are the fastest to parse. A
|
||||||
`#!cpp std::istream` comes close: the parser scans the characters its stream buffer holds in bulk, without reading
|
`#!cpp std::istream` comes close: the parser scans the characters its stream buffer holds in bulk, without reading
|
||||||
ahead, so the stream is left exactly where it would be after reading one character at a time. A `#!cpp FILE*` is
|
ahead, so the stream is left exactly where it would be after reading one character at a time. With glibc
|
||||||
read one character at a time, but the file is locked only once, so other threads that use the same `FILE` object
|
and the Apple C library, the characters the `#!cpp FILE` holds in its buffer are scanned in bulk like a stream's;
|
||||||
wait until parsing is done. See [input sources and performance](../../features/parsing/index.md#input-sources-and-performance),
|
elsewhere a `#!cpp FILE*` is read one character at a time. Where the C library has unlocked stdio functions, the
|
||||||
[`JSON_DISABLE_STREAM_BULK_SCAN`](../macros/json_disable_stream_bulk_scan.md), and
|
file is locked only once, so other threads that use the same `FILE` object wait until parsing is done, unless
|
||||||
[`JSON_DISABLE_UNLOCKED_FILE_IO`](../macros/json_disable_unlocked_file_io.md).
|
[`JSON_DISABLE_UNLOCKED_FILE_IO`](../macros/json_disable_unlocked_file_io.md) is defined to `1`. See
|
||||||
|
[input sources and performance](../../features/parsing/index.md#input-sources-and-performance) and
|
||||||
|
[`JSON_DISABLE_STREAM_BULK_SCAN`](../macros/json_disable_stream_bulk_scan.md).
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
|||||||
@@ -124,9 +124,10 @@ consumer `sax` has a super-linear complexity.
|
|||||||
|
|
||||||
A UTF-8 byte order mark is silently ignored.
|
A UTF-8 byte order mark is silently ignored.
|
||||||
|
|
||||||
When reading from a `#!c FILE*`, the file is locked while it is parsed. The lock is recursive, so the SAX handler may
|
When reading from a `#!c FILE*` where the C library has unlocked stdio functions, the file is locked while it is parsed,
|
||||||
use the same file with stdio functions, but it must not wait for another thread that uses the same `FILE` object; see
|
unless [`JSON_DISABLE_UNLOCKED_FILE_IO`](../macros/json_disable_unlocked_file_io.md) is defined to `1`.
|
||||||
[`JSON_DISABLE_UNLOCKED_FILE_IO`](../macros/json_disable_unlocked_file_io.md).
|
The lock is recursive, so the SAX handler may use the same file with stdio functions, but it must not wait for another
|
||||||
|
thread that uses the same `FILE` object.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,6 @@ The library uses the following mapping from JSON values types to BJData types ac
|
|||||||
| number_integer | 65536..2147483647 | int32 | `l` |
|
| number_integer | 65536..2147483647 | int32 | `l` |
|
||||||
| number_integer | 2147483648..4294967295 | uint32 | `m` |
|
| number_integer | 2147483648..4294967295 | uint32 | `m` |
|
||||||
| number_integer | 4294967296..9223372036854775807 | int64 | `L` |
|
| number_integer | 4294967296..9223372036854775807 | int64 | `L` |
|
||||||
| number_integer | 9223372036854775808..18446744073709551615 | uint64 | `M` |
|
|
||||||
| number_unsigned | 0..127 | int8 | `i` |
|
| number_unsigned | 0..127 | int8 | `i` |
|
||||||
| number_unsigned | 128..255 | uint8 | `U` |
|
| number_unsigned | 128..255 | uint8 | `U` |
|
||||||
| number_unsigned | 256..32767 | int16 | `I` |
|
| number_unsigned | 256..32767 | int16 | `I` |
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ specification:
|
|||||||
| number_integer | 128..255 | uint 8 | 0xCC |
|
| number_integer | 128..255 | uint 8 | 0xCC |
|
||||||
| number_integer | 256..65535 | uint 16 | 0xCD |
|
| number_integer | 256..65535 | uint 16 | 0xCD |
|
||||||
| number_integer | 65536..4294967295 | uint 32 | 0xCE |
|
| number_integer | 65536..4294967295 | uint 32 | 0xCE |
|
||||||
| number_integer | 4294967296..18446744073709551615 | uint 64 | 0xCF |
|
| number_integer | 4294967296..9223372036854775807 | uint 64 | 0xCF |
|
||||||
| number_unsigned | 0..127 | positive fixint | 0x00..0x7F |
|
| number_unsigned | 0..127 | positive fixint | 0x00..0x7F |
|
||||||
| number_unsigned | 128..255 | uint 8 | 0xCC |
|
| number_unsigned | 128..255 | uint 8 | 0xCC |
|
||||||
| number_unsigned | 256..65535 | uint 16 | 0xCD |
|
| number_unsigned | 256..65535 | uint 16 | 0xCD |
|
||||||
|
|||||||
@@ -77,9 +77,15 @@ them faster than others:
|
|||||||
|--------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------|
|
|--------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------|
|
||||||
| strings, string views, string literals, contiguous containers, pointer or iterator ranges over contiguous memory | the whole input is scanned in bulk: runs of string characters, numbers, and indentation are recognized several bytes at a time |
|
| strings, string views, string literals, contiguous containers, pointer or iterator ranges over contiguous memory | the whole input is scanned in bulk: runs of string characters, numbers, and indentation are recognized several bytes at a time |
|
||||||
| `#!cpp std::istream` (`#!cpp std::ifstream`, `#!cpp std::istringstream`, ...) | the characters the stream buffer holds are scanned in bulk like a string; the stream buffer is asked for more when they are used up |
|
| `#!cpp std::istream` (`#!cpp std::ifstream`, `#!cpp std::istringstream`, ...) | the characters the stream buffer holds are scanned in bulk like a string; the stream buffer is asked for more when they are used up |
|
||||||
| `#!cpp FILE*` | with glibc and the Apple C library, the characters the `FILE` holds in its buffer are scanned in bulk like a stream's; elsewhere one character at a time; the file is locked once for the whole parse |
|
| `#!cpp FILE*` | with glibc and the Apple C library, the characters the `FILE` holds in its buffer are scanned in bulk like a stream's; elsewhere one character at a time; where the C library has unlocked stdio functions, the file is locked once for the whole parse |
|
||||||
| other iterator ranges (e.g., `#!cpp std::list<char>`, `#!cpp std::istreambuf_iterator<char>`), wide strings | one character at a time |
|
| other iterator ranges (e.g., `#!cpp std::list<char>`, `#!cpp std::istreambuf_iterator<char>`), wide strings | one character at a time |
|
||||||
|
|
||||||
|
Defining [`JSON_DISABLE_STREAM_BULK_SCAN`](../../api/macros/json_disable_stream_bulk_scan.md) to `1` turns off the bulk
|
||||||
|
scan of a stream buffer, so a `#!cpp std::istream` is read one character at a time. Defining
|
||||||
|
[`JSON_DISABLE_UNLOCKED_FILE_IO`](../../api/macros/json_disable_unlocked_file_io.md) to `1` makes a `#!cpp FILE*` read
|
||||||
|
every character with `std::fgetc`, without locking the file for the whole parse and without the bulk scan of its buffer
|
||||||
|
(which `JSON_DISABLE_STREAM_BULK_SCAN` does not affect). Neither changes any result.
|
||||||
|
|
||||||
Input in one block of memory is read even faster with the default options (no
|
Input in one block of memory is read even faster with the default options (no
|
||||||
[parser callback](../../api/basic_json/parser_callback_t.md), no comments, no trailing commas, and for `sax_parse()`
|
[parser callback](../../api/basic_json/parser_callback_t.md), no comments, no trailing commas, and for `sax_parse()`
|
||||||
`strict = true`): `parse()`, `accept()`, and `sax_parse()` then read the grammar and the tokens in one loop over the
|
`strict = true`): `parse()`, `accept()`, and `sax_parse()` then read the grammar and the tokens in one loop over the
|
||||||
|
|||||||
@@ -27,9 +27,13 @@ A `#!cpp std::istream` (including `#!cpp std::ifstream`) gets the same bulk scan
|
|||||||
characters its stream buffer already holds (the *get area*) and asks the stream buffer for more only when they are used
|
characters its stream buffer already holds (the *get area*) and asks the stream buffer for more only when they are used
|
||||||
up. Nothing is read ahead, so the stream is left exactly where it would be after reading one character at a time, and
|
up. Nothing is read ahead, so the stream is left exactly where it would be after reading one character at a time, and
|
||||||
[`operator>>`](../api/operator_gtgt.md) can still read several values from one stream. A stream buffer without a get
|
[`operator>>`](../api/operator_gtgt.md) can still read several values from one stream. A stream buffer without a get
|
||||||
area is read one character at a time. A `#!cpp FILE*` is locked once per parse instead of once per character, and with
|
area is read one character at a time. Where the C library has unlocked stdio functions, a `#!cpp FILE*` is locked once
|
||||||
glibc and the Apple C library, the characters in its buffer are scanned in bulk as a stream's get area is. See
|
per parse instead of once per character, and with glibc and the Apple C library, the characters in its buffer are
|
||||||
[input sources and performance](parsing/index.md#input-sources-and-performance) for the full table. Parsing from a
|
scanned in bulk as a stream's get area is.
|
||||||
|
[`JSON_DISABLE_STREAM_BULK_SCAN`](../api/macros/json_disable_stream_bulk_scan.md) turns off the bulk scan of streams, and
|
||||||
|
[`JSON_DISABLE_UNLOCKED_FILE_IO`](../api/macros/json_disable_unlocked_file_io.md) both the single lock and the bulk scan
|
||||||
|
of a `#!cpp FILE*`. See [input sources and performance](parsing/index.md#input-sources-and-performance) for the full
|
||||||
|
table. Parsing from a
|
||||||
stream takes about 1.15 to 1.45 times as long as parsing an equivalent `#!cpp std::string`, which `parse()` reads with
|
stream takes about 1.15 to 1.45 times as long as parsing an equivalent `#!cpp std::string`, which `parse()` reads with
|
||||||
a parser of its own (see there).
|
a parser of its own (see there).
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user