From 860fb32d2a29fb8f69a43d913a3ea6694d036d73 Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Wed, 29 Aug 2018 14:12:49 +0200 Subject: Add move assignment and move constructor to CloneablePtr and IdentifiablePtr. This allows for use of std::unique_ptr rhs value instead of temporary raw pointer. --- vespalib/src/vespa/vespalib/util/memory.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'vespalib') diff --git a/vespalib/src/vespa/vespalib/util/memory.h b/vespalib/src/vespa/vespalib/util/memory.h index 7f51c4b553f..43be0531aec 100644 --- a/vespalib/src/vespa/vespalib/util/memory.h +++ b/vespalib/src/vespa/vespalib/util/memory.h @@ -349,6 +349,12 @@ public: } } + /** @brief move constructor, takes over ownership */ + CloneablePtr(std::unique_ptr &&rhs) + : _p(rhs.release()) + { + } + /** @brief assignment operator, does deep copy using clone() */ CloneablePtr & operator = (const CloneablePtr & rhs) { if (this != &rhs) { @@ -358,6 +364,14 @@ public: return *this; } + /** @brief move assignment operator, takes over ownership */ + CloneablePtr &operator=(std::unique_ptr &&rhs) + { + cleanup(); + _p = rhs.release(); + return *this; + } + /** @brief swap contents */ void swap(CloneablePtr & rhs) { std::swap(_p, rhs._p); } -- cgit v1.2.3