summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--staging_vespalib/src/vespa/vespalib/objects/identifiable.hpp9
-rw-r--r--vespalib/src/vespa/vespalib/util/memory.h14
2 files changed, 23 insertions, 0 deletions
diff --git a/staging_vespalib/src/vespa/vespalib/objects/identifiable.hpp b/staging_vespalib/src/vespa/vespalib/objects/identifiable.hpp
index ad31712ede9..2c34ba306ab 100644
--- a/staging_vespalib/src/vespa/vespalib/objects/identifiable.hpp
+++ b/staging_vespalib/src/vespa/vespalib/objects/identifiable.hpp
@@ -51,6 +51,15 @@ public:
IdentifiablePtr(const IdentifiablePtr &) = default;
IdentifiablePtr & operator = (const IdentifiablePtr &) = default;
IdentifiablePtr(T * p=NULL) : CloneablePtr<T>(p) { }
+ IdentifiablePtr(std::unique_ptr<T> &&rhs)
+ : CloneablePtr<T>(std::move(rhs))
+ {
+ }
+ IdentifiablePtr &operator=(std::unique_ptr<T> &&rhs)
+ {
+ CloneablePtr<T>::operator=(std::move(rhs));
+ return *this;
+ }
int cmp(const IdentifiablePtr<T> &rhs) const {
const T *a = this->get();
const T *b = rhs.get();
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<T> &&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<T> &&rhs)
+ {
+ cleanup();
+ _p = rhs.release();
+ return *this;
+ }
+
/** @brief swap contents */
void swap(CloneablePtr & rhs) { std::swap(_p, rhs._p); }