Chromium Code Reviews| Index: include/core/SkRefCnt.h |
| diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h |
| index 43251d0788c2e6a992965da626729da035d9e165..7788206e10f3d8860454f7f3d1a5294c42f39ce2 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> > |
|
bungeman-skia
2016/03/02 14:59:40
nit: don't need the extra space between '>'s anymo
hal.canary
2016/03/02 15:07:25
done
|
| + 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); |
|
bungeman-skia
2016/03/02 14:59:39
I know it's not directly related to this CL, but t
hal.canary
2016/03/02 15:07:25
Let's do that in Debug in SkSafeUnref in a separat
|
| } |
| - 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; } |