[Dune] Transition from SmartPointer to shared_ptr

Oliver Sander sander at mi.fu-berlin.de
Wed Oct 14 17:06:17 CEST 2009


Dear Dune!
Those of you reading the dune-common commit mails may have noticed
that the class SmartPointer has been deprecated, and an alternative
implementation shared_ptr has been provided instead.  This new 
implementation
is intended to completely follow the tr1 implementation of shared_ptr.
In fact, if tr1is found, the shared_ptr implementation from there is 
automatically
used.

When transitioning from SmartPointer to shared_ptr, though, you have to be
careful, because the two classes do not quite behave the same.  There 
are two
easy differences: the type SmartPointer::MemberType becomes 
shared_ptr::element_type,
und the method SmartPointer::count() is shared_ptr::use_count().  More 
problematic
is the following change:  The default constructor of SmartPointer 
allocates an
element, and hence returns a dereferenceable pointer.  
Default-constructing a
shared_ptr instead creates a pointer pointing to NULL.  This is fairly 
consistent with
regular C pointer which, when default constructed, do not reliably point 
anywhere.
However, if you rely on the SmartPointer default constructor allocating 
memory
(as for example, the SmartPointer unit test did),  THIS CHANGE WILL BREAK
YOUR CODE.

Thanks for your understanding.
Yours,
Oliver

-- 
************************************************************************
* Oliver Sander                ** email: sander at mi.fu-berlin.de        *
* Freie Universität Berlin     ** phone: + 49 (30) 838 75348           *
* Institut für Mathematik      ** URL  : page.mi.fu-berlin.de/~sander  *
* Arnimallee 6                 ** -------------------------------------*
* 14195 Berlin, Germany        ** Member of MATHEON (www.matheon.de)   *
************************************************************************





More information about the Dune mailing list