Skip to content

Commit bf75bb3

Browse files
authored
Define copy/move assignment operators
1 parent 8624408 commit bf75bb3

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

cppjson/src/object.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,25 @@ cppjson::JsonObject::JsonObject(JsonObject&& other)
1919
this->_dataType = std::exchange(other._dataType, cppjson::JsonType::Null);
2020
this->_dataStorage = std::exchange(other._dataStorage, ::operator new(DataStorageSize));
2121
}
22-
22+
cppjson::JsonObject& cppjson::JsonObject::operator=(const cppjson::JsonObject& other)
23+
{
24+
if (&other != this)
25+
{
26+
this->_dataType = other._dataType;
27+
this->_dataStorage = ::operator new(DataStorageSize);
28+
std::memcpy(this->_dataStorage, other._dataStorage, DataStorageSize);
29+
}
30+
return *this;
31+
}
32+
cppjson::JsonObject& cppjson::JsonObject::operator=(cppjson::JsonObject&& other)
33+
{
34+
if (&other != this)
35+
{
36+
this->_dataType = std::exchange(other._dataType, cppjson::JsonType::Null);
37+
this->_dataStorage = std::exchange(other._dataStorage, ::operator new(DataStorageSize));
38+
}
39+
return *this;
40+
}
2341
cppjson::JsonObject::~JsonObject()
2442
{
2543
this->Destroy();

0 commit comments

Comments
 (0)