Added operator=-workaround for pointer-assignment

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@135 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
humesikkins 2004-03-18 10:57:28 +00:00
parent 5896652d4d
commit 3cf210ef61

View file

@ -13,7 +13,6 @@
// without express or implied warranty. // without express or implied warranty.
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Last update: Mar 06, 2003
// ported RefCountedMT // ported RefCountedMT
// To create a SmartPtr with RefCountedMT as ownership policy // To create a SmartPtr with RefCountedMT as ownership policy
@ -71,6 +70,7 @@
#include "TypeManip.h" #include "TypeManip.h"
#include "MSVC6Helpers.h" #include "MSVC6Helpers.h"
#include "static_check.h" #include "static_check.h"
#include "NullType.h"
#include <functional> #include <functional>
#include <stdexcept> #include <stdexcept>
#include <cassert> #include <cassert>
@ -955,6 +955,12 @@ namespace Private
SmartPtr, const SmartPtr SmartPtr, const SmartPtr
>::Result CopyArg; >::Result CopyArg;
typedef typename Select
<
OP::destructiveCopy,
NullType, StoredType
>::Result WorkaroundType;
// i think the following two ctors have an exception-safety problem // i think the following two ctors have an exception-safety problem
// in the original version. If KP throws one can't release the resources // in the original version. If KP throws one can't release the resources
// which were possibly allocated by SP and/or OP. // which were possibly allocated by SP and/or OP.
@ -992,6 +998,10 @@ namespace Private
} }
SmartPtr(ByRef<SmartPtr> rhs)
: SP(rhs), OP(rhs), KP(rhs), CP(rhs)
{}
// do not alter the order of the following three constructors // do not alter the order of the following three constructors
// otherwise the MSVC 6.0 will fail to compile the class. // otherwise the MSVC 6.0 will fail to compile the class.
template template
@ -1021,6 +1031,7 @@ namespace Private
SmartPtr(CopyArg& rhs) SmartPtr(CopyArg& rhs)
: SP(rhs), OP(rhs), KP(rhs), CP(rhs) : SP(rhs), OP(rhs), KP(rhs), CP(rhs)
{ GetImplRef(*this) = OP::Clone(GetImplRef(rhs)); } { GetImplRef(*this) = OP::Clone(GetImplRef(rhs)); }
operator ByRef<SmartPtr>() operator ByRef<SmartPtr>()
{ return ByRef<SmartPtr>(*this); } { return ByRef<SmartPtr>(*this); }
@ -1064,6 +1075,14 @@ namespace Private
temp.Swap(*this); temp.Swap(*this);
return *this; return *this;
} }
SmartPtr& operator=(const WorkaroundType& arg)
{
SmartPtr temp(arg);
//return *this = const_cast<const SmartPtr&>(temp);
return *this = temp;
}
void Swap(SmartPtr& rhs) void Swap(SmartPtr& rhs)
{ {
OP::Swap(rhs); OP::Swap(rhs);