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 <cassert> | 8 #include <cassert> |
9 #include <iosfwd> | 9 #include <iosfwd> |
10 #include <type_traits> | |
10 | 11 |
11 #include "base/atomic_ref_count.h" | 12 #include "base/atomic_ref_count.h" |
12 #include "base/base_export.h" | 13 #include "base/base_export.h" |
13 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #ifndef NDEBUG | 16 #ifndef NDEBUG |
16 #include "base/logging.h" | 17 #include "base/logging.h" |
17 #endif | 18 #endif |
18 #include "base/threading/thread_collision_warner.h" | 19 #include "base/threading/thread_collision_warner.h" |
19 #include "build/build_config.h" | 20 #include "build/build_config.h" |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 AddRef(ptr_); | 277 AddRef(ptr_); |
277 } | 278 } |
278 | 279 |
279 // Copy constructor. | 280 // Copy constructor. |
280 scoped_refptr(const scoped_refptr<T>& r) : ptr_(r.ptr_) { | 281 scoped_refptr(const scoped_refptr<T>& r) : ptr_(r.ptr_) { |
281 if (ptr_) | 282 if (ptr_) |
282 AddRef(ptr_); | 283 AddRef(ptr_); |
283 } | 284 } |
284 | 285 |
285 // Copy conversion constructor. | 286 // Copy conversion constructor. |
286 template <typename U> | 287 template <typename U, |
288 typename Dummy = typename std::enable_if< | |
danakj
2016/04/19 23:19:46
nit: don't need to name it Dummy, just "typename =
piman
2016/04/19 23:24:49
Done.
| |
289 std::is_convertible<U*, T*>::value>::type> | |
287 scoped_refptr(const scoped_refptr<U>& r) : ptr_(r.get()) { | 290 scoped_refptr(const scoped_refptr<U>& r) : ptr_(r.get()) { |
288 if (ptr_) | 291 if (ptr_) |
289 AddRef(ptr_); | 292 AddRef(ptr_); |
290 } | 293 } |
291 | 294 |
292 // Move constructor. This is required in addition to the conversion | 295 // Move constructor. This is required in addition to the conversion |
293 // constructor below in order for clang to warn about pessimizing moves. | 296 // constructor below in order for clang to warn about pessimizing moves. |
294 scoped_refptr(scoped_refptr&& r) : ptr_(r.get()) { r.ptr_ = nullptr; } | 297 scoped_refptr(scoped_refptr&& r) : ptr_(r.get()) { r.ptr_ = nullptr; } |
295 | 298 |
296 // Move conversion constructor. | 299 // Move conversion constructor. |
297 template <typename U> | 300 template <typename U, |
301 typename Dummy = typename std::enable_if< | |
danakj
2016/04/19 23:19:46
ditto
piman
2016/04/19 23:24:49
Done.
| |
302 std::is_convertible<U*, T*>::value>::type> | |
298 scoped_refptr(scoped_refptr<U>&& r) : ptr_(r.get()) { | 303 scoped_refptr(scoped_refptr<U>&& r) : ptr_(r.get()) { |
299 r.ptr_ = nullptr; | 304 r.ptr_ = nullptr; |
300 } | 305 } |
301 | 306 |
302 ~scoped_refptr() { | 307 ~scoped_refptr() { |
303 if (ptr_) | 308 if (ptr_) |
304 Release(ptr_); | 309 Release(ptr_); |
305 } | 310 } |
306 | 311 |
307 T* get() const { return ptr_; } | 312 T* get() const { return ptr_; } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
445 bool operator!=(const T* lhs, const scoped_refptr<U>& rhs) { | 450 bool operator!=(const T* lhs, const scoped_refptr<U>& rhs) { |
446 return !operator==(lhs, rhs); | 451 return !operator==(lhs, rhs); |
447 } | 452 } |
448 | 453 |
449 template <typename T> | 454 template <typename T> |
450 std::ostream& operator<<(std::ostream& out, const scoped_refptr<T>& p) { | 455 std::ostream& operator<<(std::ostream& out, const scoped_refptr<T>& p) { |
451 return out << p.get(); | 456 return out << p.get(); |
452 } | 457 } |
453 | 458 |
454 #endif // BASE_MEMORY_REF_COUNTED_H_ | 459 #endif // BASE_MEMORY_REF_COUNTED_H_ |
OLD | NEW |