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

Side by Side Diff: Source/wtf/NonNullPtr.h

Issue 23890025: WIP (Introduce WTF::NonNullPtr<T>.) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « Source/wtf/Forward.h ('k') | Source/wtf/wtf.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #ifndef NonNullPtr_h
2 #define NonNullPtr_h
3
4 #include "wtf/Assertions.h"
5
6 namespace WTF {
7
8 template<typename T> class NonNullPtr {
9 public:
10 NonNullPtr(T* ptr) : m_ptr(ptr) { ASSERT(m_ptr); }
11 NonNullPtr(const NonNullPtr& other) : m_ptr(other.m_ptr) { ASSERT(m_ptr); }
12 // For non-const -> const conversion, derived class -> base class conversion .
13 template<typename U> NonNullPtr(const NonNullPtr<U>& other) : m_ptr(other.ge t()) { ASSERT(m_ptr); }
14 T* operator->() const { return m_ptr; }
15 T* get() const { return m_ptr; }
16 NonNullPtr& operator=(T* ptr)
17 {
18 ASSERT(ptr);
19 m_ptr = ptr;
20 }
21
22 private:
23 T* m_ptr;
24 };
25
26
27 template<typename T, typename U> inline bool operator==(const NonNullPtr<T>& a, const NonNullPtr<U>& b) { return a.get() == b.get(); }
28 template<typename T, typename U> inline bool operator!=(const NonNullPtr<T>& a, const NonNullPtr<U>& b) { return a.get() != b.get(); }
29 template<typename T, typename U> inline bool operator==(const NonNullPtr<T>& a, U* b) { return a.get() == b; }
30 template<typename T, typename U> inline bool operator!=(const NonNullPtr<T>& a, U* b) { return a.get() != b; }
31 template<typename T, typename U> inline bool operator==(T* a, const NonNullPtr<U >& b) { return a == b.get(); }
32 template<typename T, typename U> inline bool operator!=(T* a, const NonNullPtr<U >& b) { return a != b.get(); }
33
34
35 }
36
37 using WTF::NonNullPtr;
38
39 #endif
OLDNEW
« no previous file with comments | « Source/wtf/Forward.h ('k') | Source/wtf/wtf.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698