Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Unified Diff: include/core/SkRefCnt.h

Issue 1752093002: sk_sp: Covariant Move Constructor and Move Assignment (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: no more space between > > Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/RefCntTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkRefCnt.h
diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h
index 43251d0788c2e6a992965da626729da035d9e165..e6be8bb9eff82fa81db359859583ec73cb6816cb 100644
--- a/include/core/SkRefCnt.h
+++ b/include/core/SkRefCnt.h
@@ -246,6 +246,9 @@ public:
* created sk_sp both have a reference to it.
*/
sk_sp(const sk_sp<T>& that) : fPtr(SkSafeRef(that.get())) {}
+ template <typename U,
+ typename = skstd::enable_if_t<skstd::is_convertible<U, T>::value>>
+ sk_sp(const sk_sp<U>& that) : fPtr(SkSafeRef(that.get())) {}
/**
* Move the underlying object from the argument to the newly created sk_sp. Afterwards only
@@ -253,6 +256,9 @@ public:
* No call to ref() or unref() will be made.
*/
sk_sp(sk_sp<T>&& that) : fPtr(that.release()) {}
+ template <typename U,
+ typename = skstd::enable_if_t<skstd::is_convertible<U, T>::value>>
+ sk_sp(sk_sp<U>&& that) : fPtr(that.release()) {}
/**
* Adopt the bare pointer into the newly created sk_sp.
@@ -267,7 +273,7 @@ public:
SkSafeUnref(fPtr);
}
- sk_sp<T>& operator=(std::nullptr_t) { this->reset(); }
+ sk_sp<T>& operator=(std::nullptr_t) { this->reset(); return *this; }
/**
* Shares the underlying object referenced by the argument by calling ref() on it. If this
@@ -278,6 +284,12 @@ public:
this->reset(SkSafeRef(that.get()));
return *this;
}
+ template <typename U,
+ typename = skstd::enable_if_t<skstd::is_convertible<U, T>::value>>
+ sk_sp<T>& operator=(const sk_sp<U>& that) {
+ this->reset(SkSafeRef(that.get()));
+ return *this;
+ }
/**
* Move the underlying object from the argument to the sk_sp. If the sk_sp previously held
@@ -288,12 +300,20 @@ public:
this->reset(that.release());
return *this;
}
+ template <typename U,
+ typename = skstd::enable_if_t<skstd::is_convertible<U, T>::value>>
+ sk_sp<T>& operator=(sk_sp<U>&& that) {
+ this->reset(that.release());
+ return *this;
+ }
bool operator==(std::nullptr_t) const { return this->get() == nullptr; }
bool operator!=(std::nullptr_t) const { return this->get() != nullptr; }
- bool operator==(const sk_sp<T>& that) const { return this->get() == that.get(); }
- bool operator!=(const sk_sp<T>& that) const { return this->get() != that.get(); }
+ template <typename U>
+ bool operator==(const sk_sp<U>& that) const { return this->get() == that.get(); }
+ template <typename U>
+ bool operator!=(const sk_sp<U>& that) const { return this->get() != that.get(); }
explicit operator bool() const { return this->get() != nullptr; }
« no previous file with comments | « no previous file | tests/RefCntTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698