Added support for policy based explicit/implicit constructor

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@131 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
rani_sharoni 2003-08-21 12:55:14 +00:00
parent 36a53ca896
commit 30b3c736af

View file

@ -779,10 +779,27 @@ namespace Loki
SmartPtr, const SmartPtr>::Result
CopyArg;
private:
struct NeverMatched;
#ifdef LOKI_SMARTPTR_CONVERSION_CONSTRUCTOR_POLICY
typedef typename Select< CP::allow, const StoredType&, NeverMatched>::Result ImplicitArg;
typedef typename Select<!CP::allow, const StoredType&, NeverMatched>::Result ExplicitArg;
#else
typedef const StoredType& ImplicitArg;
typedef typename Select<false, const StoredType&, NeverMatched>::Result ExplicitArg;
#endif
public:
SmartPtr()
{ KP::OnDefault(GetImpl(*this)); }
SmartPtr(const StoredType& p) : SP(p)
explicit
SmartPtr(ExplicitArg p) : SP(p)
{ KP::OnInit(GetImpl(*this)); }
SmartPtr(ImplicitArg p) : SP(p)
{ KP::OnInit(GetImpl(*this)); }
SmartPtr(CopyArg& rhs)
@ -1231,6 +1248,14 @@ namespace std
// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
// December 09, 2001: Included <cassert>
// February 2, 2003: fixed dependent names - credit due to Rani Sharoni
// August 21, 2003: Added support for policy based explicit/implicit constructor.
// The new code will be effective if a macro named
// *** LOKI_SMARTPTR_CONVERSION_CONSTRUCTOR_POLICY ***
// is defined (due to backward computability concerns).
// In case that the macro is defined and the conversion policy allow flag is off
// (e.g. DisallowConversion) then the conversion from the "pointer" to the
// SmartPtr must be explicit.
////////////////////////////////////////////////////////////////////////////////
#endif // SMARTPTR_INC_