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

Side by Side Diff: base/memory/ref_counted.h

Issue 609593004: Add an explicit bool conversion to scoped_refptr<T>. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix WMI? Created 6 years, 2 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 unified diff | Download patch
« no previous file with comments | « no previous file | base/memory/ref_counted_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 } 296 }
297 297
298 T* get() const { return ptr_; } 298 T* get() const { return ptr_; }
299 299
300 #if !defined(DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR) 300 #if !defined(DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR)
301 // Allow scoped_refptr<C> to be used in boolean expression 301 // Allow scoped_refptr<C> to be used in boolean expression
302 // and comparison operations. 302 // and comparison operations.
303 operator T*() const { return ptr_; } 303 operator T*() const { return ptr_; }
304 #endif 304 #endif
305 305
306 explicit operator bool() const { return ptr_ != nullptr; }
307
306 T& operator*() const { 308 T& operator*() const {
307 assert(ptr_ != NULL); 309 assert(ptr_ != nullptr);
308 return *ptr_; 310 return *ptr_;
309 } 311 }
310 312
311 T* operator->() const { 313 T* operator->() const {
312 assert(ptr_ != NULL); 314 assert(ptr_ != nullptr);
313 return ptr_; 315 return ptr_;
314 } 316 }
315 317
316 scoped_refptr<T>& operator=(T* p) { 318 scoped_refptr<T>& operator=(T* p) {
317 // AddRef first so that self assignment should work 319 // AddRef first so that self assignment should work
318 if (p) 320 if (p)
319 p->AddRef(); 321 p->AddRef();
320 T* old_ptr = ptr_; 322 T* old_ptr = ptr_;
321 ptr_ = p; 323 ptr_ = p;
322 if (old_ptr) 324 if (old_ptr)
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 return !operator==(lhs, rhs); 395 return !operator==(lhs, rhs);
394 } 396 }
395 397
396 template <typename T> 398 template <typename T>
397 std::ostream& operator<<(std::ostream& out, const scoped_refptr<T>& p) { 399 std::ostream& operator<<(std::ostream& out, const scoped_refptr<T>& p) {
398 return out << p.get(); 400 return out << p.get();
399 } 401 }
400 #endif // defined(DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR) 402 #endif // defined(DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR)
401 403
402 #endif // BASE_MEMORY_REF_COUNTED_H_ 404 #endif // BASE_MEMORY_REF_COUNTED_H_
OLDNEW
« 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