[vtk-developers] std::auto_ptr replacement for modern compilers.

Shawn Waldon shawn.waldon at kitware.com
Sun Jun 19 11:29:26 EDT 2016


Hi Andrew,

We have had a few discussions about this and here is (roughly) where I
think things stand.  (To the list: feel free to correct/expand this).
> So I have two questions:
> 1) How do we handle future proofing in this case? Most importantly, we
need to keep std::auto_ptr for older compilers but should move to either
std::unique_ptr and/or possibly std::shared_ptr. Is there a define that we
can use?

Yes std::unique_ptr is the right replacement, but we should check if the
compiler/library supports it and fall back to std::auto_ptr.  I don't know
of a define that could be used to test this, though one could be added.

> Finally:
> 2) vtkSmartPointer ... how does this fit in? To me it seems this similar
to std::shared_ptr. Could vtkSmartPointer just be a wrapper around
std::shared_ptr for new compilers (C++11 and newer)?

This was a long discussion, but the summary is this: vtkSmartPointer
assumes that the object itself is reference counted internally and will
delete itself when that count reaches 0.  std::shared_ptr assumes that it
needs to keep the reference count and delete the object when that reaches
0.  These two different takes on reference counting are hard to reconcile
and there isn't really a way to easily migrate to use std::shared_ptr.  It
is also uncertain if we want to...

Shawn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20160619/fef4a8a4/attachment.html>


More information about the vtk-developers mailing list