Skip to content

Switch to copy-and-swap idiom for operator=. #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions include/json/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class JSON_API Value {
CZString(const char *cstr, DuplicationPolicy allocate);
CZString(const CZString &other);
~CZString();
CZString &operator=(const CZString &other);
CZString &operator=(CZString other);
bool operator<(const CZString &other) const;
bool operator==(const CZString &other) const;
ArrayIndex index() const;
Expand Down Expand Up @@ -238,7 +238,7 @@ Json::Value obj_value(Json::objectValue); // {}
Value(const Value &other);
~Value();

Value &operator=(const Value &other);
Value &operator=(Value other);
/// Swap values.
/// \note Currently, comments are intentionally not swapped, for
/// both logic and efficiency.
Expand Down Expand Up @@ -681,7 +681,7 @@ class JSON_API ValueInternalMap {

ValueInternalMap();
ValueInternalMap(const ValueInternalMap &other);
ValueInternalMap &operator=(const ValueInternalMap &other);
ValueInternalMap &operator=(ValueInternalMap other);
~ValueInternalMap();

void swap(ValueInternalMap &other);
Expand Down Expand Up @@ -775,7 +775,7 @@ class JSON_API ValueInternalArray {

ValueInternalArray();
ValueInternalArray(const ValueInternalArray &other);
ValueInternalArray &operator=(const ValueInternalArray &other);
ValueInternalArray &operator=(ValueInternalArray other);
~ValueInternalArray();
void swap(ValueInternalArray &other);

Expand Down
5 changes: 2 additions & 3 deletions src/lib_json/json_internalarray.inl
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,9 @@ ValueInternalArray::ValueInternalArray( const ValueInternalArray &other )


ValueInternalArray &
ValueInternalArray::operator =( const ValueInternalArray &other )
ValueInternalArray::operator=(ValueInternalArray other)
{
ValueInternalArray temp( other );
swap( temp );
swap(other);
return *this;
}

Expand Down
5 changes: 2 additions & 3 deletions src/lib_json/json_internalmap.inl
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,9 @@ ValueInternalMap::ValueInternalMap( const ValueInternalMap &other )


ValueInternalMap &
ValueInternalMap::operator =( const ValueInternalMap &other )
ValueInternalMap::operator=(ValueInternalMap other)
{
ValueInternalMap dummy( other );
swap( dummy );
swap(other);
return *this;
}

Expand Down
10 changes: 4 additions & 6 deletions src/lib_json/json_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,8 @@ void Value::CZString::swap(CZString &other) {
std::swap(index_, other.index_);
}

Value::CZString &Value::CZString::operator=(const CZString &other) {
CZString temp(other);
swap(temp);
Value::CZString &Value::CZString::operator=(CZString other) {
swap(other);
return *this;
}

Expand Down Expand Up @@ -482,9 +481,8 @@ Value::~Value() {
delete[] comments_;
}

Value &Value::operator=(const Value &other) {
Value temp(other);
swap(temp);
Value &Value::operator=(Value other) {
swap(other);
return *this;
}

Expand Down