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> |
10 #include <cassert> | 11 #include <cassert> |
11 #include <iosfwd> | 12 #include <iosfwd> |
12 #include <type_traits> | 13 #include <type_traits> |
13 | 14 |
14 #include "base/atomic_ref_count.h" | 15 #include "base/atomic_ref_count.h" |
15 #include "base/base_export.h" | 16 #include "base/base_export.h" |
16 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
17 #include "base/logging.h" | 18 #include "base/logging.h" |
18 #include "base/macros.h" | 19 #include "base/macros.h" |
19 #include "base/threading/thread_collision_warner.h" | 20 #include "base/threading/thread_collision_warner.h" |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 scoped_refptr<T>(std::move(r)).swap(*this); | 348 scoped_refptr<T>(std::move(r)).swap(*this); |
348 return *this; | 349 return *this; |
349 } | 350 } |
350 | 351 |
351 template <typename U> | 352 template <typename U> |
352 scoped_refptr<T>& operator=(scoped_refptr<U>&& r) { | 353 scoped_refptr<T>& operator=(scoped_refptr<U>&& r) { |
353 scoped_refptr<T>(std::move(r)).swap(*this); | 354 scoped_refptr<T>(std::move(r)).swap(*this); |
354 return *this; | 355 return *this; |
355 } | 356 } |
356 | 357 |
357 void swap(T** pp) { | 358 void swap(scoped_refptr<T>& r) { std::swap(ptr_, r.ptr_); } |
358 T* p = ptr_; | |
359 ptr_ = *pp; | |
360 *pp = p; | |
361 } | |
362 | |
363 void swap(scoped_refptr<T>& r) { | |
364 swap(&r.ptr_); | |
365 } | |
366 | 359 |
367 explicit operator bool() const { return ptr_ != nullptr; } | 360 explicit operator bool() const { return ptr_ != nullptr; } |
368 | 361 |
369 template <typename U> | 362 template <typename U> |
370 bool operator==(const scoped_refptr<U>& rhs) const { | 363 bool operator==(const scoped_refptr<U>& rhs) const { |
371 return ptr_ == rhs.get(); | 364 return ptr_ == rhs.get(); |
372 } | 365 } |
373 | 366 |
374 template <typename U> | 367 template <typename U> |
375 bool operator!=(const scoped_refptr<U>& rhs) const { | 368 bool operator!=(const scoped_refptr<U>& rhs) const { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 bool operator!=(std::nullptr_t null, const scoped_refptr<T>& rhs) { | 448 bool operator!=(std::nullptr_t null, const scoped_refptr<T>& rhs) { |
456 return !operator==(null, rhs); | 449 return !operator==(null, rhs); |
457 } | 450 } |
458 | 451 |
459 template <typename T> | 452 template <typename T> |
460 std::ostream& operator<<(std::ostream& out, const scoped_refptr<T>& p) { | 453 std::ostream& operator<<(std::ostream& out, const scoped_refptr<T>& p) { |
461 return out << p.get(); | 454 return out << p.get(); |
462 } | 455 } |
463 | 456 |
464 #endif // BASE_MEMORY_REF_COUNTED_H_ | 457 #endif // BASE_MEMORY_REF_COUNTED_H_ |
OLD | NEW |