Jelajahi Sumber

libobs: Support move for mismatched ComPtr

jpark37 4 tahun lalu
induk
melakukan
23f43f46db
1 mengubah file dengan 12 tambahan dan 0 penghapusan
  1. 12 0
      libobs/util/windows/ComPtr.hpp

+ 12 - 0
libobs/util/windows/ComPtr.hpp

@@ -58,6 +58,10 @@ public:
 			ptr->AddRef();
 	}
 	inline ComPtr(ComPtr<T> &&c) noexcept : ptr(c.ptr) { c.ptr = nullptr; }
+	template<class U>
+	inline ComPtr(ComPtr<U> &&c) noexcept : ptr(c.Detach())
+	{
+	}
 	inline ~ComPtr() { Kill(); }
 
 	inline void Clear()
@@ -91,6 +95,14 @@ public:
 		return *this;
 	}
 
+	template<class U> inline ComPtr<T> &operator=(ComPtr<U> &&c) noexcept
+	{
+		Kill();
+		ptr = c.Detach();
+
+		return *this;
+	}
+
 	inline T *Detach()
 	{
 		T *out = ptr;