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

Unified Diff: base/memory/weak_ptr.h

Issue 1863643002: Add a std::nullptr_t constructor to base::WeakPtr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: format Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/memory/weak_ptr_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/weak_ptr.h
diff --git a/base/memory/weak_ptr.h b/base/memory/weak_ptr.h
index 006e1fd33fdf7c1585b19b1ddb7dfeb5a245692e..3b8bcb1b077607f36224fa52837e72161f3ed295 100644
--- a/base/memory/weak_ptr.h
+++ b/base/memory/weak_ptr.h
@@ -3,7 +3,7 @@
// found in the LICENSE file.
// Weak pointers are pointers to an object that do not affect its lifetime,
-// and which may be invalidated (i.e. reset to NULL) by the object, or its
+// and which may be invalidated (i.e. reset to nullptr) by the object, or its
// owner, at any time, most commonly when the object is about to be deleted.
// Weak pointers are useful when an object needs to be accessed safely by one
@@ -70,6 +70,7 @@
#ifndef BASE_MEMORY_WEAK_PTR_H_
#define BASE_MEMORY_WEAK_PTR_H_
+#include <cstddef>
#include <type_traits>
#include "base/base_export.h"
@@ -199,8 +200,9 @@ template <typename T> class WeakPtrFactory;
template <typename T>
class WeakPtr : public internal::WeakPtrBase {
public:
- WeakPtr() : ptr_(NULL) {
- }
+ WeakPtr() : ptr_(nullptr) {}
+
+ WeakPtr(std::nullptr_t) : ptr_(nullptr) {}
// Allow conversion from U to T provided U "is a" T. Note that this
// is separate from the (implicit) copy constructor.
@@ -208,20 +210,20 @@ class WeakPtr : public internal::WeakPtrBase {
WeakPtr(const WeakPtr<U>& other) : WeakPtrBase(other), ptr_(other.ptr_) {
}
- T* get() const { return ref_.is_valid() ? ptr_ : NULL; }
+ T* get() const { return ref_.is_valid() ? ptr_ : nullptr; }
T& operator*() const {
- DCHECK(get() != NULL);
+ DCHECK(get() != nullptr);
return *get();
}
T* operator->() const {
- DCHECK(get() != NULL);
+ DCHECK(get() != nullptr);
return get();
}
void reset() {
ref_ = internal::WeakReference();
- ptr_ = NULL;
+ ptr_ = nullptr;
}
// Implement "Safe Bool Idiom"
@@ -246,7 +248,7 @@ class WeakPtr : public internal::WeakPtrBase {
typedef T* WeakPtr::*Testable;
public:
- operator Testable() const { return get() ? &WeakPtr::ptr_ : NULL; }
+ operator Testable() const { return get() ? &WeakPtr::ptr_ : nullptr; }
private:
// Explicitly declare comparison operators as required by the "Safe Bool
@@ -265,7 +267,7 @@ class WeakPtr : public internal::WeakPtrBase {
}
// This pointer is only valid when ref_.is_valid() is true. Otherwise, its
- // value is undefined (as opposed to NULL).
+ // value is undefined (as opposed to nullptr).
T* ptr_;
};
@@ -280,9 +282,7 @@ class WeakPtrFactory {
explicit WeakPtrFactory(T* ptr) : ptr_(ptr) {
}
- ~WeakPtrFactory() {
- ptr_ = NULL;
- }
+ ~WeakPtrFactory() { ptr_ = nullptr; }
WeakPtr<T> GetWeakPtr() {
DCHECK(ptr_);
« no previous file with comments | « no previous file | base/memory/weak_ptr_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698