summaryrefslogtreecommitdiff
path: root/zen/com_ptr.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:21:59 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:21:59 +0200
commitd4af25c52a28b93484ffb55e0a8027bc4ce7856f (patch)
tree853d57468d6b370711e7a5dd2c3dc7d5bac81b10 /zen/com_ptr.h
parent5.8 (diff)
downloadFreeFileSync-d4af25c52a28b93484ffb55e0a8027bc4ce7856f.tar.gz
FreeFileSync-d4af25c52a28b93484ffb55e0a8027bc4ce7856f.tar.bz2
FreeFileSync-d4af25c52a28b93484ffb55e0a8027bc4ce7856f.zip
5.9
Diffstat (limited to 'zen/com_ptr.h')
-rw-r--r--zen/com_ptr.h24
1 files changed, 12 insertions, 12 deletions
diff --git a/zen/com_ptr.h b/zen/com_ptr.h
index bb52b5cb..030a0801 100644
--- a/zen/com_ptr.h
+++ b/zen/com_ptr.h
@@ -34,16 +34,16 @@ template <class T>
class ComPtr
{
public:
- ComPtr() : ptr(nullptr) {}
+ ComPtr() : ptr(nullptr) {} //
+ ComPtr(const ComPtr& other) : ptr(other.ptr) { if (ptr) ptr->AddRef(); } //noexcept in C++11
+ ComPtr( ComPtr&& other) : ptr(other.ptr) { other.ptr = nullptr; } //
+ ~ComPtr() { if (ptr) ptr->Release(); } //has exception spec of compiler-generated destructor by default
- ComPtr(const ComPtr& other) : ptr(other.ptr) { if (ptr) ptr->AddRef(); }
- ComPtr( ComPtr&& other) : ptr(other.ptr) { other.ptr = nullptr; }
+ ComPtr& operator=(const ComPtr& other) { ComPtr(other).swap(*this); return *this; } //noexcept in C++11
+ ComPtr& operator=(ComPtr&& tmp) { swap(tmp); return *this; } //
+ //don't use unifying assignment but save one move-construction in the r-value case instead!
- ~ComPtr() { if (ptr) ptr->Release(); }
-
- ComPtr& operator=(ComPtr other) { swap(other); return *this; } //unifying assignment: no need for r-value reference assignment!
-
- void swap(ComPtr& rhs) { std::swap(ptr, rhs.ptr); } //throw()
+ void swap(ComPtr& rhs) { std::swap(ptr, rhs.ptr); } //noexcept in C++11
T** init() //get pointer for use with ::CoCreateInstance()
{
@@ -56,7 +56,7 @@ public:
T* operator->() const { return ptr; }
T& operator* () const { return *ptr; }
- T* release() //throw()
+ T* release() //noexcept in C++11
{
T* tmp = ptr;
ptr = nullptr;
@@ -74,7 +74,7 @@ public:
template <class S, class T>
-ComPtr<S> com_dynamic_cast(const ComPtr<T>& other); //throw()
+ComPtr<S> com_dynamic_cast(const ComPtr<T>& other); //noexcept in C++11
@@ -99,7 +99,7 @@ ComPtr<S> com_dynamic_cast(const ComPtr<T>& other); //throw()
//################# implementation #############################
-//we cannot specialize std::swap() for a class template and are not allowed to overload it => offer swap in own namespace
+//we cannot partially specialize std::swap() for a class template and are not allowed to overload it => offer swap in own namespace
template <class T> inline
void swap(zen::ComPtr<T>& lhs, zen::ComPtr<T>& rhs)
{
@@ -108,7 +108,7 @@ void swap(zen::ComPtr<T>& lhs, zen::ComPtr<T>& rhs)
template <class S, class T> inline
-ComPtr<S> com_dynamic_cast(const ComPtr<T>& other) //throw()
+ComPtr<S> com_dynamic_cast(const ComPtr<T>& other) //noexcept in C++11
{
ComPtr<S> outPtr;
if (other)
bgstack15