aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar Ben Wagner <bungeman@google.com>2018-05-28 13:35:39 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-05-30 18:54:38 +0000
commit5d1adbfae9ee59051f564c004b1097f845fad324 (patch)
treee3ff48fe119a1df78218a1618e4f7bb4d18102ba /include
parent342480e46657754b0121031000b4c0a6d1b50890 (diff)
Make sk_sp operator bool explicit.
The sk_sp class has been using the operator pointer to field as a c++98 version of explicit operator bool. This change updates this class to use explicit operator bool. The one visible change is that the pointer to field version isn't quite as explcit, requiring code changes for some users. Change-Id: Iddf8fb347b1d3ec33db1af08489c9fd885c9bf08 Reviewed-on: https://skia-review.googlesource.com/130380 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
Diffstat (limited to 'include')
-rw-r--r--include/core/SkRefCnt.h15
1 files changed, 7 insertions, 8 deletions
diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h
index 0c3b23a7d1..eebc9684de 100644
--- a/include/core/SkRefCnt.h
+++ b/include/core/SkRefCnt.h
@@ -13,6 +13,7 @@
#include <atomic>
#include <functional>
#include <memory>
+#include <ostream>
#include <type_traits>
#include <utility>
@@ -244,8 +245,6 @@ private:
* may have its ref/unref be thread-safe, but that is not assumed/imposed by sk_sp.
*/
template <typename T> class sk_sp {
- /** Supports safe bool idiom. Obsolete with explicit operator bool. */
- using unspecified_bool_type = T* sk_sp::*;
public:
using element_type = T;
@@ -322,12 +321,7 @@ public:
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; }
- bool operator!() const { return this->get() == nullptr; }
+ explicit operator bool() const { return this->get() != nullptr; }
T* get() const { return fPtr; }
T* operator->() const { return fPtr; }
@@ -432,6 +426,11 @@ template <typename T> inline bool operator>=(std::nullptr_t, const sk_sp<T>& b)
return !(nullptr < b);
}
+template <typename C, typename CT, typename T>
+auto operator<<(std::basic_ostream<C, CT>& os, const sk_sp<T>& sp) -> decltype(os << sp.get()) {
+ return os << sp.get();
+}
+
template <typename T, typename... Args>
sk_sp<T> sk_make_sp(Args&&... args) {
return sk_sp<T>(new T(std::forward<Args>(args)...));