Bug 1191354 part 10 - More features for OwningNonNull; r=froydnj
authorAryeh Gregor <ayg@aryeh.name>
Sun, 01 May 2016 16:15:39 +0300
changeset 295648 62d58efcd0c078ab11cae082be3a04bc6ca69810
parent 295647 12906c848272a720d5275f31eb1546a4a2b4a199
child 295649 3739ead5ce63c9cdec7a3b7fc11ade4c37efacbd
push id19015
push usercbook@mozilla.com
push dateMon, 02 May 2016 09:39:23 +0000
treeherderfx-team@2080375bc69d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1191354
milestone49.0a1
Bug 1191354 part 10 - More features for OwningNonNull; r=froydnj
xpcom/base/OwningNonNull.h
--- a/xpcom/base/OwningNonNull.h
+++ b/xpcom/base/OwningNonNull.h
@@ -26,16 +26,22 @@ public:
   }
 
   template<class U>
   MOZ_IMPLICIT OwningNonNull(already_AddRefed<U>&& aValue)
   {
     init(aValue);
   }
 
+  template<class U>
+  MOZ_IMPLICIT OwningNonNull(const OwningNonNull<U>& aValue)
+  {
+    init(aValue);
+  }
+
   // This is no worse than get() in terms of const handling.
   operator T&() const
   {
     MOZ_ASSERT(mInited);
     MOZ_ASSERT(mPtr, "OwningNonNull<T> was set to null");
     return *mPtr;
   }
 
@@ -66,34 +72,53 @@ public:
 
   OwningNonNull<T>&
   operator=(T& aValue)
   {
     init(&aValue);
     return *this;
   }
 
+  template<class U>
   OwningNonNull<T>&
-  operator=(already_AddRefed<T>&& aValue)
+  operator=(already_AddRefed<U>&& aValue)
+  {
+    init(aValue);
+    return *this;
+  }
+
+  template<class U>
+  OwningNonNull<T>&
+  operator=(const OwningNonNull<U>& aValue)
   {
     init(aValue);
     return *this;
   }
 
   // Don't allow assigning nullptr, it makes no sense
   void operator=(decltype(nullptr)) = delete;
 
   already_AddRefed<T> forget()
   {
 #ifdef DEBUG
     mInited = false;
 #endif
     return mPtr.forget();
   }
 
+  template<class U>
+  void
+  forget(U** aOther)
+  {
+#ifdef DEBUG
+    mInited = false;
+#endif
+    mPtr.forget(aOther);
+  }
+
   // Make us work with smart pointer helpers that expect a get().
   T* get() const
   {
     MOZ_ASSERT(mInited);
     MOZ_ASSERT(mPtr);
     return mPtr;
   }