Skip to content

Commit e7cf44d

Browse files
Add move constructor to json class for efficient resource transfer
1 parent 65ab59d commit e7cf44d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

include/json.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ namespace json
7575
* @param other The json object to be copied.
7676
*/
7777
json(const json &other) : value(other.value) {}
78+
/**
79+
* @brief Move constructor for the json class.
80+
*
81+
* This constructor transfers ownership of the value from another json object to the new json object.
82+
*
83+
* @param other The json object to be moved.
84+
*/
85+
json(json &&other) noexcept : value(std::move(other.value)) { other.value = nullptr; }
7886

7987
/**
8088
* @brief Constructs a JSON object from a value of type T.

0 commit comments

Comments
 (0)