+ implemented member and non-member swap

This commit is contained in:
Niels 2015-01-19 19:51:07 +01:00
parent 7724d34741
commit a144800774
4 changed files with 154 additions and 4 deletions

View file

@ -34,7 +34,6 @@ due to alignment.
@bug Numbers are currently handled too generously. There are several formats
that are forbidden by the standard, but are accepted by the parser.
@todo Implement json::swap()
@todo Implement json::insert(), json::emplace(), json::emplace_back, json::erase
@todo Implement json::reverse_iterator, json::const_reverse_iterator,
json::rbegin(), json::rend(), json::crbegin(), json::crend()?
@ -178,6 +177,7 @@ class json
operator std::string() const;
/// implicit conversion to integer (only for numbers)
operator int() const;
operator long() const;
/// implicit conversion to double (only for numbers)
operator double() const;
/// implicit conversion to Boolean (only for Booleans)
@ -289,6 +289,9 @@ class json
/// removes all elements from compounds and resets values to default
void clear() noexcept;
/// swaps content with other object
void swap(json&) noexcept;
/// return the type of the object
value_type type() const noexcept;
@ -418,7 +421,7 @@ class json
/// read the next character, stripping whitespace
bool next();
/// raise an exception with an error message
inline void error(const std::string&) const __attribute__((noreturn));
[[noreturn]] inline void error(const std::string&) const;
/// parse a quoted string
inline std::string parseString();
/// transforms a unicode codepoint to it's UTF-8 presentation
@ -450,6 +453,19 @@ class json
/// user-defined literal operator to create JSON objects from strings
nlohmann::json operator "" _json(const char*, std::size_t);
// specialization of std::swap
namespace std
{
template <>
/// swaps the values of two JSON objects
inline void swap(nlohmann::json& j1,
nlohmann::json& j2) noexcept(is_nothrow_move_constructible<nlohmann::json>::value and
is_nothrow_move_assignable<nlohmann::json>::value)
{
j1.swap(j2);
}
}
/*!
@file
@copyright The code is licensed under the MIT License
@ -1720,6 +1736,12 @@ void json::clear() noexcept
}
}
void json::swap(json& o) noexcept
{
std::swap(type_, o.type_);
std::swap(value_, o.value_);
}
json::value_type json::type() const noexcept
{
return type_;