diff --git a/include/caosdb/utility.h b/include/caosdb/utility.h index 43586da27258311470241097d536bdeb7c58c772..d7497e4658ba620096a78a6f0269ef16ebd0b379 100644 --- a/include/caosdb/utility.h +++ b/include/caosdb/utility.h @@ -137,14 +137,14 @@ public: * * Also moves the `wrapped` object. */ - JsonValue(JsonValue &&other) = default; + JsonValue(JsonValue &&other); /** * Move Assigment. * * Also moves the `wrapped` object. */ - auto operator=(JsonValue &&other) -> JsonValue & = default; + auto operator=(JsonValue &&other) -> JsonValue &; /** * Return true if the `wrapped` object is the nullptr. diff --git a/src/caosdb/utility.cpp b/src/caosdb/utility.cpp index 7aed71621b7c8a04b332bd785e5aeee4a8dfa26b..58d7c9736945fd9439b2aea0f902761713d919ba 100644 --- a/src/caosdb/utility.cpp +++ b/src/caosdb/utility.cpp @@ -147,10 +147,11 @@ auto load_json_file(const path &json_file) -> JsonValue { JsonValue::~JsonValue() { this->Reset(); } auto JsonValue::Reset() -> void { - if (!IsNull()) { - delete static_cast<value *>(this->wrapped); - } + void * tmp = std::move(this->wrapped); this->wrapped = nullptr; + if (tmp != nullptr) { + delete static_cast<value *>(tmp); + } } JsonValue::JsonValue(const JsonValue &other) : wrapped(nullptr) { @@ -169,4 +170,21 @@ auto JsonValue::operator=(const JsonValue &other) -> JsonValue & { return *this; } +JsonValue::JsonValue(JsonValue &&other) : wrapped(nullptr) { + std::cout << "MoveConstructor" << std::endl; + if (!other.IsNull()) { + this->wrapped = other.wrapped; + other.wrapped = nullptr; + } +} + +auto JsonValue::operator=(JsonValue &&other) -> JsonValue & { + std::cout << "MoveAssignment" << std::endl; + if (this != &other) { + this->wrapped = other.wrapped; + other.wrapped = nullptr; + } + return *this; +} + } // namespace caosdb::utility