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

Side by Side Diff: third_party/WebKit/Source/wtf/UniquePtrTransitionGuide.md

Issue 2547053003: s/ passed(...) / WTF::passed(...) / to avoid future ambiguity w/ base::Passed. (Closed)
Patch Set: Rebasing... Created 4 years 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
OLDNEW
1 # std::unique_ptr Transition Guide 1 # std::unique_ptr Transition Guide
2 2
3 Now `std::unique_ptr<T>` is available anywhere in Blink. This document goes thro ugh various use cases of `OwnPtr<T>` 3 Now `std::unique_ptr<T>` is available anywhere in Blink. This document goes thro ugh various use cases of `OwnPtr<T>`
4 and how they get converted to `std::unique_ptr<T>` so you can smoothly switch yo ur mind. 4 and how they get converted to `std::unique_ptr<T>` so you can smoothly switch yo ur mind.
5 5
6 If you have any uncertainties on using `std::unique_ptr<T>`, ask yutak@chromium. org (or other C++ gurus around you) 6 If you have any uncertainties on using `std::unique_ptr<T>`, ask yutak@chromium. org (or other C++ gurus around you)
7 for help. 7 for help.
8 8
9 ## Creation and Use 9 ## Creation and Use
10 10
(...skipping 12 matching lines...) Expand all
23 T* leakedPointer = owned.leakPtr(); 23 T* leakedPointer = owned.leakPtr();
24 } 24 }
25 ``` 25 ```
26 26
27 #### std::unique_ptr 27 #### std::unique_ptr
28 28
29 ```c++ 29 ```c++
30 void f() 30 void f()
31 { 31 {
32 std::unique_ptr<T> owned(new T(argument)); 32 std::unique_ptr<T> owned(new T(argument));
33 // Or: auto owned = wrapUnique(new T(argument)); †1 33 // Or: auto owned = WTF::wrapUnique(new T(argument)); †1
34 owned->useThis(); 34 owned->useThis();
35 T& reference = *owned; 35 T& reference = *owned;
36 T* pointer = owned.get(); 36 T* pointer = owned.get();
37 owned.reset(); // Or: owned = nullptr 37 owned.reset(); // Or: owned = nullptr
38 owned.reset(new T); // Or: owned = wrapUnique(new T) 38 owned.reset(new T); // Or: owned = WTF::wrapUnique(new T)
39 T* leakedPointer = owned.release(); 39 T* leakedPointer = owned.release();
40 } 40 }
41 ``` 41 ```
42 |||---||| 42 |||---|||
43 43
44 †1 `wrapUnique()` is particularly useful when you pass a `unique_ptr` to somebod y else: 44 †1 `WTF::wrapUnique()` is particularly useful when you pass a `unique_ptr` to so mebody else:
45 45
46 ```c++ 46 ```c++
47 std::unique_ptr<T> g() 47 std::unique_ptr<T> g()
48 { 48 {
49 h(wrapUnique(new T(argument))); // Pass to a function. 49 h(WTF::wrapUnique(new T(argument))); // Pass to a function.
50 return wrapUnique(new T(argument)); // Return from a function. 50 return WTF::wrapUnique(new T(argument)); // Return from a function.
51 } 51 }
52 52
53 ``` 53 ```
54 54
55 You need to `#include "wtf/PtrUtil.h"` for `wrapUnique()`. 55 You need to `#include "wtf/PtrUtil.h"` for `WTF::wrapUnique()`.
56 56
57 ## Passing and Receiving 57 ## Passing and Receiving
58 58
59 |||---||| 59 |||---|||
60 #### OwnPtr 60 #### OwnPtr
61 61
62 ```c++ 62 ```c++
63 void receive(PassOwnPtr<T> object) 63 void receive(PassOwnPtr<T> object)
64 { 64 {
65 OwnPtr<T> localObject = object; 65 OwnPtr<T> localObject = object;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 an lvalue. This is possible because `return` makes all the local variables go aw ay by going back to the caller. 147 an lvalue. This is possible because `return` makes all the local variables go aw ay by going back to the caller.
148 148
149 *** aside 149 *** aside
150 *Note:* Well, yes, I know, the definitions of lvalues and rvalues here are not v ery precise. However, the above 150 *Note:* Well, yes, I know, the definitions of lvalues and rvalues here are not v ery precise. However, the above
151 understandings are sufficient in practice. If you want to know further, see 151 understandings are sufficient in practice. If you want to know further, see
152 [the wiki about value categories at cppreference.com](http://en.cppreference.com /w/cpp/language/value_category). 152 [the wiki about value categories at cppreference.com](http://en.cppreference.com /w/cpp/language/value_category).
153 153
154 See also [Dana's guide for rvalue references](https://sites.google.com/a/chromiu m.org/dev/rvalue-references) 154 See also [Dana's guide for rvalue references](https://sites.google.com/a/chromiu m.org/dev/rvalue-references)
155 if you want to learn about move semantics. 155 if you want to learn about move semantics.
156 *** 156 ***
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/TerminatedArray.h ('k') | third_party/WebKit/Source/wtf/VectorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698