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

Unified Diff: mojo/public/cpp/bindings/struct_ptr.h

Issue 828373008: Allow constructing {Interface,Struct}Ptr from nullptr (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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
Index: mojo/public/cpp/bindings/struct_ptr.h
diff --git a/mojo/public/cpp/bindings/struct_ptr.h b/mojo/public/cpp/bindings/struct_ptr.h
index efcf255e3ae7d454067758d30aab592b33ffc9df..60f3c87415afb7d28b01ecfab54e7b9efc006ac2 100644
--- a/mojo/public/cpp/bindings/struct_ptr.h
+++ b/mojo/public/cpp/bindings/struct_ptr.h
@@ -27,16 +27,23 @@ class StructHelper {
template <typename Struct>
class StructPtr {
- MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(StructPtr, RValue);
+ MOJO_MOVE_ONLY_TYPE(StructPtr)
public:
StructPtr() : ptr_(nullptr) {}
+ StructPtr(decltype(nullptr)) : ptr_(nullptr) {}
+
~StructPtr() { delete ptr_; }
- StructPtr(RValue other) : ptr_(nullptr) { Take(other.object); }
- StructPtr& operator=(RValue other) {
- Take(other.object);
+ StructPtr& operator=(decltype(nullptr)) {
+ reset();
+ return *this;
+ }
+
+ StructPtr(StructPtr&& other) : ptr_(nullptr) { Take(&other); }
+ StructPtr& operator=(StructPtr&& other) {
+ Take(&other);
return *this;
}
@@ -101,16 +108,16 @@ class StructPtr {
// Designed to be used when Struct is small and copyable.
template <typename Struct>
class InlinedStructPtr {
- MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(InlinedStructPtr, RValue);
+ MOJO_MOVE_ONLY_TYPE(InlinedStructPtr);
public:
InlinedStructPtr() : is_null_(true) {}
~InlinedStructPtr() {}
darin (slow to review) 2015/01/14 18:38:07 don't you need the nullptr ctor and assignment ope
jamesr 2015/01/14 18:39:30 Hmm yes - I didn't find a user of this but it'd be
- InlinedStructPtr(RValue other) : is_null_(true) { Take(other.object); }
- InlinedStructPtr& operator=(RValue other) {
- Take(other.object);
+ InlinedStructPtr(InlinedStructPtr&& other) : is_null_(true) { Take(&other); }
+ InlinedStructPtr& operator=(InlinedStructPtr&& other) {
+ Take(&other);
return *this;
}

Powered by Google App Engine
This is Rietveld 408576698