diff --git a/include/json/value.h b/include/json/value.h index 6b40831..ba7365c 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -233,7 +233,12 @@ private: CZString(CZString&& other); #endif ~CZString(); - CZString& operator=(CZString other); + CZString& operator=(const CZString& other); + +#if JSON_HAS_RVALUE_REFERENCES + CZString& operator=(CZString&& other); +#endif + bool operator<(CZString const& other) const; bool operator==(CZString const& other) const; ArrayIndex index() const; @@ -447,7 +452,7 @@ Json::Value obj_value(Json::objectValue); // {} /// Equivalent to jsonvalue[jsonvalue.size()] = value; Value& append(const Value& value); -#ifdef JSON_HAS_RVALUE_REFERENCES +#if JSON_HAS_RVALUE_REFERENCES Value& append(Value&& value); #endif diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index adae5a1..5f5cf8b 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -292,11 +292,21 @@ void Value::CZString::swap(CZString& other) { std::swap(index_, other.index_); } -Value::CZString& Value::CZString::operator=(CZString other) { - swap(other); +Value::CZString& Value::CZString::operator=(const CZString& other) { + cstr_ = other.cstr_; + index_ = other.index_; return *this; } +#if JSON_HAS_RVALUE_REFERENCES +Value::CZString& Value::CZString::operator=(CZString&& other) { + cstr_ = other.cstr_; + index_ = other.index_; + other.cstr_ = nullptr; + return *this; +} +#endif + bool Value::CZString::operator<(const CZString& other) const { if (!cstr_) return index_ < other.index_; //return strcmp(cstr_, other.cstr_) < 0; @@ -1145,7 +1155,7 @@ Value const& Value::operator[](CppTL::ConstString const& key) const Value& Value::append(const Value& value) { return (*this)[size()] = value; } -#ifdef JSON_HAS_RVALUE_REFERENCES +#if JSON_HAS_RVALUE_REFERENCES Value& Value::append(Value&& value) { return (*this)[size()] = value; } #endif