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

Unified Diff: base/memory/ref_counted.h

Issue 510323002: Disable scoped_refptr operator T* on Linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Exclude OS_CHROMEOS Created 6 years, 3 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 | base/memory/ref_counted_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/ref_counted.h
diff --git a/base/memory/ref_counted.h b/base/memory/ref_counted.h
index 96329cb1f49954adb375d82617019ee067f76c30..cb22fde66129c88e73d0126706b7e314f5a859ac 100644
--- a/base/memory/ref_counted.h
+++ b/base/memory/ref_counted.h
@@ -6,6 +6,7 @@
#define BASE_MEMORY_REF_COUNTED_H_
#include <cassert>
+#include <iosfwd>
#include "base/atomic_ref_count.h"
#include "base/base_export.h"
@@ -14,6 +15,11 @@
#include "base/logging.h"
#endif
#include "base/threading/thread_collision_warner.h"
+#include "build/build_config.h"
+
+#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
+#define DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR
+#endif
namespace base {
@@ -291,9 +297,11 @@ class scoped_refptr {
T* get() const { return ptr_; }
+#if !defined(DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR)
// Allow scoped_refptr<C> to be used in boolean expression
// and comparison operations.
operator T*() const { return ptr_; }
+#endif
T& operator*() const {
assert(ptr_ != NULL);
@@ -335,6 +343,23 @@ class scoped_refptr {
swap(&r.ptr_);
}
+#if defined(DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR)
+ template <typename U>
+ bool operator==(const scoped_refptr<U>& rhs) const {
+ return ptr_ == rhs.get();
+ }
+
+ template <typename U>
+ bool operator!=(const scoped_refptr<U>& rhs) const {
+ return !operator==(rhs);
+ }
+
+ template <typename U>
+ bool operator<(const scoped_refptr<U>& rhs) const {
+ return ptr_ < rhs.get();
+ }
+#endif
+
protected:
T* ptr_;
};
@@ -346,4 +371,32 @@ scoped_refptr<T> make_scoped_refptr(T* t) {
return scoped_refptr<T>(t);
}
+#if defined(DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR)
+// Temporary operator overloads to facilitate the transition...
+template <typename T, typename U>
+bool operator==(const scoped_refptr<T>& lhs, const U* rhs) {
+ return lhs.get() == rhs;
+}
+
+template <typename T, typename U>
+bool operator==(const T* lhs, const scoped_refptr<U>& rhs) {
+ return lhs == rhs.get();
+}
+
+template <typename T, typename U>
+bool operator!=(const scoped_refptr<T>& lhs, const U* rhs) {
+ return !operator==(lhs, rhs);
+}
+
+template <typename T, typename U>
+bool operator!=(const T* lhs, const scoped_refptr<U>& rhs) {
+ return !operator==(lhs, rhs);
+}
+
+template <typename T>
+std::ostream& operator<<(std::ostream& out, const scoped_refptr<T>& p) {
+ return out << p.get();
+}
+#endif // defined(DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR)
+
#endif // BASE_MEMORY_REF_COUNTED_H_
« no previous file with comments | « no previous file | base/memory/ref_counted_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698