Chromium Code Reviews| Index: include/core/SkRefCnt.h |
| diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h |
| index cea72cda66f9a6bdad350a4c398d67d654c56385..d9591c893210681f7e02de30f4c19ebb8aecc267 100644 |
| --- a/include/core/SkRefCnt.h |
| +++ b/include/core/SkRefCnt.h |
| @@ -238,6 +238,7 @@ private: |
| * may have its ref/unref be thread-safe, but that is not assumed/imposed by sk_sp. |
| */ |
| template <typename T> class sk_sp { |
| + using unspecified_bool_type = T* sk_sp::*; |
|
mtklein
2016/03/02 20:05:10
// safe bool idiom. obsolete with explicit operat
bungeman-skia
2016/03/02 20:32:58
Done.
|
| public: |
| sk_sp() : fPtr(nullptr) {} |
| sk_sp(std::nullptr_t) : fPtr(nullptr) {} |
| @@ -316,10 +317,16 @@ public: |
| template <typename U> |
| bool operator!=(const sk_sp<U>& that) const { return this->get() != that.get(); } |
| + T& operator*() const { |
| + SkASSERT(this->get() != nullptr); |
| + return *this->get(); |
| + } |
| + |
| // MSVC 2013 does not work correctly with explicit operator bool. |
| // https://chromium-cpp.appspot.com/#core-blacklist |
| + // When explicit operator bool can be used, remove operator! and operator unspecified_bool_type. |
| //explicit operator bool() const { return this->get() != nullptr; } |
| - |
| + operator unspecified_bool_type() const { return this->get() ? &sk_sp::fPtr : nullptr; } |
|
mtklein
2016/03/02 20:05:10
... ? &fPtr : nullptr ...
?
bungeman-skia
2016/03/02 20:32:58
So it turns out the type of '&fPtr' here is 'T*con
|
| bool operator!() const { return this->get() == nullptr; } |
| T* get() const { return fPtr; } |