[Dune] Transition from SmartPointer to shared_ptr

Jö Fahlke jorrit at jorrit.de
Wed Oct 14 18:54:18 CEST 2009


Am Wed, 14. Oct 2009, 18:31:17 +0200 schrieb Markus Blatt:
> Back to the change of smartpointer:
> 
> Of course I rely on the behaviour of the old implementation!
> Hopefully nobody changed ArrayList which used the old smartpointer and
> relied on it. Otherwise parallel ISTL is broken :/

How making SmartPointer a wrapper around shared_ptr?  That way, SmartPointer
and shared_ptr can be made interoperable, i.e. you can set a SmartPointer from
a shared_ptr and the other way round.  The constructor of the wrapper can
implement the SmartPointer semantic.  This way we can use SmartPointer and
shared_ptr in parallel.  Of course, SmartPointer should still be deprecated,
since it is rather pointless to have two classes doing essentially the same
thing, but now you don't have to migrade every piece of code touching the same
entity referenced by a smart pointer at once.

I thought of something along the lines of:

template<typename T>
class SmartPointer
  : public shared_ptr<T>
{
public:
  SmartPointer(T* other = new T())
    : shared_ptr<T>(other)
  {}
  SmartPointer(const shared_ptr<T>& other)
    : shared_ptr<T>(other)
  {}
  // wrap other constructors as neccessary

  int count() const
  { return use_count(); }

  operator shared_ptr<T>&()
  { return *this; }
  operator const shared_ptr<T>&() const
  { return *this; }
};

Bye,
Jö.

-- 
F: Was ist der Sinn des Menschen?
A: Die Menschheit voranzubringen.
F: Aber was ist der Sinn der Menschheit?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 828 bytes
Desc: Digital signature
URL: <https://lists.dune-project.org/pipermail/dune/attachments/20091014/63ea24f0/attachment.sig>


More information about the Dune mailing list