Chromium Code Reviews| Index: base/memory/ref_counted.h |
| diff --git a/base/memory/ref_counted.h b/base/memory/ref_counted.h |
| index 96329cb1f49954adb375d82617019ee067f76c30..5102ed8d2823f16f0b701fbc7250f1398724a61e 100644 |
| --- a/base/memory/ref_counted.h |
| +++ b/base/memory/ref_counted.h |
| @@ -15,6 +15,10 @@ |
| #endif |
| #include "base/threading/thread_collision_warner.h" |
| +#if defined(OS_LINUX) |
|
Ryan Sleevi
2014/09/04 21:29:04
1) Shouldn't you explicitly include build/build_co
dcheng
2014/09/04 21:36:17
1) Done.
2) I thought they were mutually exclusive
|
| +#define DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR |
| +#endif |
| + |
| namespace base { |
| namespace subtle { |
| @@ -291,9 +295,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 +341,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 +369,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) { |
|
Ryan Sleevi
2014/08/28 18:42:51
Don't you need iosfwd included when NDEBUG isn't s
dcheng
2014/09/04 21:36:17
Done.
|
| + return out << p.get(); |
| +} |
| +#endif // defined(DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR) |
| + |
| #endif // BASE_MEMORY_REF_COUNTED_H_ |