OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_MEMORY_REF_COUNTED_H_ | 5 #ifndef BASE_MEMORY_REF_COUNTED_H_ |
6 #define BASE_MEMORY_REF_COUNTED_H_ | 6 #define BASE_MEMORY_REF_COUNTED_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <algorithm> | |
11 #include <cassert> | 10 #include <cassert> |
12 #include <iosfwd> | 11 #include <iosfwd> |
13 #include <type_traits> | 12 #include <type_traits> |
14 | 13 |
15 #include "base/atomic_ref_count.h" | 14 #include "base/atomic_ref_count.h" |
16 #include "base/base_export.h" | 15 #include "base/base_export.h" |
17 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
18 #include "base/logging.h" | 17 #include "base/logging.h" |
19 #include "base/macros.h" | 18 #include "base/macros.h" |
20 #include "base/threading/thread_collision_warner.h" | 19 #include "base/threading/thread_collision_warner.h" |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 scoped_refptr<T>(std::move(r)).swap(*this); | 347 scoped_refptr<T>(std::move(r)).swap(*this); |
349 return *this; | 348 return *this; |
350 } | 349 } |
351 | 350 |
352 template <typename U> | 351 template <typename U> |
353 scoped_refptr<T>& operator=(scoped_refptr<U>&& r) { | 352 scoped_refptr<T>& operator=(scoped_refptr<U>&& r) { |
354 scoped_refptr<T>(std::move(r)).swap(*this); | 353 scoped_refptr<T>(std::move(r)).swap(*this); |
355 return *this; | 354 return *this; |
356 } | 355 } |
357 | 356 |
358 void swap(scoped_refptr<T>& r) { std::swap(ptr_, r.ptr_); } | 357 void swap(T** pp) { |
| 358 T* p = ptr_; |
| 359 ptr_ = *pp; |
| 360 *pp = p; |
| 361 } |
| 362 |
| 363 void swap(scoped_refptr<T>& r) { |
| 364 swap(&r.ptr_); |
| 365 } |
359 | 366 |
360 explicit operator bool() const { return ptr_ != nullptr; } | 367 explicit operator bool() const { return ptr_ != nullptr; } |
361 | 368 |
362 template <typename U> | 369 template <typename U> |
363 bool operator==(const scoped_refptr<U>& rhs) const { | 370 bool operator==(const scoped_refptr<U>& rhs) const { |
364 return ptr_ == rhs.get(); | 371 return ptr_ == rhs.get(); |
365 } | 372 } |
366 | 373 |
367 template <typename U> | 374 template <typename U> |
368 bool operator!=(const scoped_refptr<U>& rhs) const { | 375 bool operator!=(const scoped_refptr<U>& rhs) const { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 bool operator!=(std::nullptr_t null, const scoped_refptr<T>& rhs) { | 455 bool operator!=(std::nullptr_t null, const scoped_refptr<T>& rhs) { |
449 return !operator==(null, rhs); | 456 return !operator==(null, rhs); |
450 } | 457 } |
451 | 458 |
452 template <typename T> | 459 template <typename T> |
453 std::ostream& operator<<(std::ostream& out, const scoped_refptr<T>& p) { | 460 std::ostream& operator<<(std::ostream& out, const scoped_refptr<T>& p) { |
454 return out << p.get(); | 461 return out << p.get(); |
455 } | 462 } |
456 | 463 |
457 #endif // BASE_MEMORY_REF_COUNTED_H_ | 464 #endif // BASE_MEMORY_REF_COUNTED_H_ |
OLD | NEW |