]> git.tdb.fi Git - libs/core.git/blobdiff - source/core/refptr.h
Add move semantics to Variant
[libs/core.git] / source / core / refptr.h
index 34560ec0389beea43bbfb66fe2db1bd111bb954a..1a164c1a90eafe69d3eab755b971400ff1f3e275 100644 (file)
@@ -10,10 +10,8 @@ struct RefCounts
                KEEP = 1U<<(sizeof(unsigned)*8-1)
        };
 
-       unsigned count;
-       unsigned weak_count;
-
-       RefCounts(): count(0), weak_count(0) { }
+       unsigned count = 0;
+       unsigned weak_count = 0;
 };
 
 template<typename T>
@@ -151,6 +149,9 @@ template<typename T>
 template<typename U>
 RefPtr<T> &RefPtr<T>::assign(const RefPtr<U> &p)
 {
+       if(static_cast<const void *>(&p)==this)
+               return *this;
+
        decref();
        data = p.data;
        counts = p.counts;
@@ -195,6 +196,9 @@ template<typename T>
 template<typename U>
 WeakPtr<T> &WeakPtr<T>::assign(const WeakPtr<U> &p)
 {
+       if(&p==this)
+               return *this;
+
        decref();
        data = p.get();
        counts = (data ? p.counts : nullptr);