This commit is contained in:
nlohmann committed 2026-10-27 12:14:00 +00:00
1 parent b36f8a9821
commit 11a863958e
1180 files changed
+14211 -6025

No files matched your search

+5 -5
View File
@@ -12,7 +12,7 @@ bool operator==(const BasicJsonType& lhs, const basic_json_view& rhs);
1. Compares two views for equality: whether the values [`BasicJsonType::parse()`](https://json.nlohmann.me/api/basic_json/parse/index.md) would produce for `lhs` and `rhs` are equal, according to `BasicJsonType`'s [`operator==`](https://json.nlohmann.me/api/basic_json/operator_eq/index.md).
1. Compares a view and a `BasicJsonType` value for equality, in either order: whether the value `parse()` would produce for the view and the other operand are equal, according to `BasicJsonType`'s [`operator==`](https://json.nlohmann.me/api/basic_json/operator_eq/index.md).
Neither overload builds a `BasicJsonType` value for a view to do the comparison (see [Notes](#notes) below). Numbers compare by value across their types (`1 == 1.0`), and an object compares by its members, with duplicate keys resolved exactly as `parse()` resolves them -- the last value, at the position of the first occurrence of the key. This is not what [`operator[]`](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/index.md) and the other lookups return for a duplicate key: they find the *first* member (see [Duplicate keys](https://json.nlohmann.me/features/json_view/#duplicate-keys)).
Neither overload builds a `BasicJsonType` value for a view to do the comparison (see [Notes](#notes) below). Numbers compare by value across their types (`1 == 1.0`), and an object compares by its members, with duplicate keys resolved exactly as `parse()` resolves them — the last value, at the position of the first occurrence of the key. This is not what [`operator[]`](https://json.nlohmann.me/api/basic_json_view/operator%5B%5D/index.md) and the other lookups return for a duplicate key: they find the *first* member (see [Duplicate keys](https://json.nlohmann.me/features/json_view/#duplicate-keys)).
## Parameters
@@ -38,7 +38,7 @@ Linear in the size of the compared values: every number, string, array element,
## Notes
Only a single number, boolean, or `null` value is ever materialized into a `BasicJsonType`, to reuse its `operator==` -- for numbers, so that values written differently in the source text but equal in value (e.g. an integer and a floating-point literal) still compare equal, following the same rules `BasicJsonType` does for special values such as `NaN`. Constructing one of these scalars never allocates. Strings are compared directly, without allocating, either from the source text on both sides or, for overload 2, against `BasicJsonType`'s own string. Arrays and objects are never materialized at all; only their elements or members are visited, one pair at a time.
Only a single number, boolean, or `null` value is ever materialized into a `BasicJsonType`, to reuse its `operator==` — for numbers, so that values written differently in the source text but equal in value (e.g. an integer and a floating-point literal) still compare equal, following the same rules `BasicJsonType` does for special values such as `NaN`. Constructing one of these scalars never allocates. Strings are compared directly, without allocating, either from the source text on both sides or, for overload 2, against `BasicJsonType`'s own string. Arrays and objects are never materialized at all; only their elements or members are visited, one pair at a time.
How objects are compared
@@ -54,7 +54,7 @@ No ordering comparison (`operator<`) is provided for `basic_json_view`; [`materi
Example
The example below checks whether a newly received configuration differs from the previous one, and whether a received document matches what a test expects -- directly on views, without ever materializing a `BasicJsonType` value for either side.
The example below checks whether a newly received configuration differs from the previous one, and whether a received document matches what a test expects — directly on views, without ever materializing a `BasicJsonType` value for either side.
```
#include <iostream>
@@ -99,8 +99,8 @@ true
## See also
- [operator!=](https://json.nlohmann.me/api/basic_json_view/operator_ne/index.md) - compare for inequality
- [materialize](https://json.nlohmann.me/api/basic_json_view/materialize/index.md) - build a `BasicJsonType` value, e.g. to keep comparing after the document is gone
- [`operator!=`](https://json.nlohmann.me/api/basic_json_view/operator_ne/index.md) - compare for inequality
- [`materialize`](https://json.nlohmann.me/api/basic_json_view/materialize/index.md) - build a `BasicJsonType` value, e.g. to keep comparing after the document is gone
- [`BasicJsonType::operator==`](https://json.nlohmann.me/api/basic_json/operator_eq/index.md) - the corresponding function of `basic_json`
## Version history