1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-28 12:02:00 +03:00

Use swap() by ADL (#3609)

* Use swap() by ADL

* Add type to swap() exception messages
This commit is contained in:
Florian Albrechtskirchinger
2022-07-28 21:51:45 +02:00
committed by GitHub
parent 298e4a9449
commit a714381a5f
3 changed files with 35 additions and 25 deletions

View File

@ -3447,11 +3447,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
// swap only works for arrays
if (JSON_HEDLEY_LIKELY(is_array()))
{
std::swap(*(m_value.array), other);
using std::swap;
swap(*(m_value.array), other);
}
else
{
JSON_THROW(type_error::create(310, detail::concat("cannot use swap() with ", type_name()), this));
JSON_THROW(type_error::create(310, detail::concat("cannot use swap(array_t&) with ", type_name()), this));
}
}
@ -3462,11 +3463,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
// swap only works for objects
if (JSON_HEDLEY_LIKELY(is_object()))
{
std::swap(*(m_value.object), other);
using std::swap;
swap(*(m_value.object), other);
}
else
{
JSON_THROW(type_error::create(310, detail::concat("cannot use swap() with ", type_name()), this));
JSON_THROW(type_error::create(310, detail::concat("cannot use swap(object_t&) with ", type_name()), this));
}
}
@ -3477,11 +3479,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
// swap only works for strings
if (JSON_HEDLEY_LIKELY(is_string()))
{
std::swap(*(m_value.string), other);
using std::swap;
swap(*(m_value.string), other);
}
else
{
JSON_THROW(type_error::create(310, detail::concat("cannot use swap() with ", type_name()), this));
JSON_THROW(type_error::create(310, detail::concat("cannot use swap(string_t&) with ", type_name()), this));
}
}
@ -3492,11 +3495,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
// swap only works for strings
if (JSON_HEDLEY_LIKELY(is_binary()))
{
std::swap(*(m_value.binary), other);
using std::swap;
swap(*(m_value.binary), other);
}
else
{
JSON_THROW(type_error::create(310, detail::concat("cannot use swap() with ", type_name()), this));
JSON_THROW(type_error::create(310, detail::concat("cannot use swap(binary_t&) with ", type_name()), this));
}
}
@ -3507,11 +3511,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
// swap only works for strings
if (JSON_HEDLEY_LIKELY(is_binary()))
{
std::swap(*(m_value.binary), other);
using std::swap;
swap(*(m_value.binary), other);
}
else
{
JSON_THROW(type_error::create(310, detail::concat("cannot use swap() with ", type_name()), this));
JSON_THROW(type_error::create(310, detail::concat("cannot use swap(binary_t::container_type&) with ", type_name()), this));
}
}