This commit is contained in:
nlohmann committed 2026-11-18 23:40:28 +00:00
1 parent 70feeb496c
commit 8279f43a4b
471 files changed
+1737 -1335

No files matched your search

+14 -2
View File
@@ -2,12 +2,21 @@
```cpp
namespace std {
void swap(nlohmann::basic_json& j1, nlohmann::basic_json& j2);
void swap(nlohmann::basic_json& j1, nlohmann::basic_json& j2) noexcept(
is_nothrow_move_constructible<nlohmann::basic_json>::value &&
is_nothrow_move_assignable<nlohmann::basic_json>::value
);
}
```
Exchanges the values of two JSON objects.
This specialization is only provided before C++20, which no longer allows specializing function templates in
namespace `std`. With C++20 (and in generic code with any standard), use the idiom `#!cpp using std::swap; swap(j1, j2);`: it finds
the [`swap`](swap.md) friend function (overload 2) by argument-dependent lookup. A qualified `#!cpp std::swap(j1, j2)`
still compiles with C++20, but uses the generic `std::swap`, which swaps by three moves instead of exchanging the
contents.
## Parameters
`j1` (in, out)
@@ -18,7 +27,9 @@ Exchanges the values of two JSON objects.
## Exception safety
No-throw guarantee: this function never throws exceptions.
No-throw guarantee if the `noexcept` condition above holds: it holds unless moving the
[`json_base_class_t`](json_base_class_t.md) can throw. With the default base class, this function never throws
exceptions.
## Complexity
@@ -78,3 +89,4 @@ void swap(nlohmann::basic_json& j1, nlohmann::basic_json& j2)
- Added in version 1.0.0.
- Extended for arbitrary basic_json types in version 3.10.5.
- Not provided with C++20 since version 3.9.0.