Improve Json::Value special members (fixes RIPD-215):

* Add move special members
* Fix Json::Value::swap
This commit is contained in:
Howard Hinnant
2014-04-18 13:39:40 -04:00
committed by Vinnie Falco
parent 73c5a867c6
commit b5348980e2
3 changed files with 87 additions and 1 deletions

View File

@@ -554,16 +554,49 @@ Value::operator= ( const Value& other )
return *this;
}
Value::Value ( Value&& other )
: value_ ( other.value_ )
, type_ ( other.type_ )
, allocated_ ( other.allocated_ )
# ifdef JSON_VALUE_USE_INTERNAL_MAP
, itemIsUsed_ ( other.itemIsUsed_ )
, memberNameIsStatic_ ( other.memberNameIsStatic_ )
#endif // JSON_VALUE_USE_INTERNAL_MAP
, comments_ ( other.comments_ )
{
std::memset( &other, 0, sizeof(Value) );
}
Value&
Value::operator= ( Value&& other )
{
swap ( other );
return *this;
}
void
Value::swap ( Value& other )
{
std::swap ( value_, other.value_ );
ValueType temp = type_;
type_ = other.type_;
other.type_ = temp;
std::swap ( value_, other.value_ );
int temp2 = allocated_;
allocated_ = other.allocated_;
other.allocated_ = temp2;
# ifdef JSON_VALUE_USE_INTERNAL_MAP
unsigned temp3 = itemIsUsed_;
itemIsUsed_ = other.itemIsUsed_;
other.itemIsUsed_ = itemIsUsed_;
temp2 = memberNameIsStatic_;
memberNameIsStatic_ = other.memberNameIsStatic_;
other.memberNameIsStatic_ = temp2
# endif
std::swap(comments_, other.comments_);
}
ValueType