mirror of
https://github.com/nlohmann/json.git
synced 2025-07-31 10:24:23 +03:00
Disable std::swap specialization in C++20 and added a friend swap function
This commit is contained in:
@ -5865,6 +5865,34 @@ class basic_json
|
||||
/*!
|
||||
@brief exchanges the values
|
||||
|
||||
Exchanges the contents of the JSON value from @a left with those of @a right. Does not
|
||||
invoke any move, copy, or swap operations on individual elements. All
|
||||
iterators and references remain valid. The past-the-end iterator is
|
||||
invalidated. implemented as a friend function callable via ADL.
|
||||
|
||||
@param[in,out] left JSON value to exchange the contents with
|
||||
@param[in,out] right JSON value to exchange the contents with
|
||||
|
||||
@complexity Constant.
|
||||
|
||||
@liveexample{The example below shows how JSON values can be swapped with
|
||||
`swap()`.,swap__reference}
|
||||
|
||||
@since version 1.0.0
|
||||
*/
|
||||
friend void swap(reference left, reference right) noexcept (
|
||||
std::is_nothrow_move_constructible<value_t>::value and
|
||||
std::is_nothrow_move_assignable<value_t>::value and
|
||||
std::is_nothrow_move_constructible<json_value>::value and
|
||||
std::is_nothrow_move_assignable<json_value>::value
|
||||
)
|
||||
{
|
||||
left.swap(right);
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief exchanges the values
|
||||
|
||||
Exchanges the contents of a JSON array with those of @a other. Does not
|
||||
invoke any move, copy, or swap operations on individual elements. All
|
||||
iterators and references remain valid. The past-the-end iterator is
|
||||
@ -8635,6 +8663,9 @@ struct less<::nlohmann::detail::value_t>
|
||||
}
|
||||
};
|
||||
|
||||
// C++20 prohibit function specialization in the std namespace.
|
||||
#ifndef JSON_HAS_CPP_20
|
||||
|
||||
/*!
|
||||
@brief exchanges the values of two JSON objects
|
||||
|
||||
@ -8649,6 +8680,8 @@ inline void swap<nlohmann::json>(nlohmann::json& j1, nlohmann::json& j2) noexcep
|
||||
j1.swap(j2);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace std
|
||||
|
||||
/*!
|
||||
|
Reference in New Issue
Block a user