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

Andrew Maclean andrew.amaclean at gmail.com
Sun Jun 19 03:35:00 EDT 2016


This is just for discussion!

However if someone gives me guidance I am willing to do the work.

While building VTK I noticed a warning regarding the deprecation of
std::auto_ptr.

It seems std::auto_ptr is deprecated since C++11 and will most likely be
removed in C++17.
See: http://en.cppreference.com/w/cpp/memory/auto_ptr
and: https://en.wikipedia.org/wiki/C%2B%2B17

>From a quick read it seems that std::unique_ptr is the preferred
replacement. However there is also an std::shared_ptr which is a smart
pointer retaining shared ownership of an object through a pointer.

A cursory search reveals that the following VTK sources use std::auto_ptr:
./ThirdParty/jsoncpp/vtkjsoncpp/jsoncpp.cpp
./IO/XMLParser/vtkXMLDataParser.cxx
./IO/XML/vtkXMLWriter.cxx
./Common/DataModel/vtkDispatcher_Private.h

It seems ./Utilities/KWSys/vtksys/auto_ptr.hxx.in implements its own
version of auto_ptr, however this is not used in the above files.

I'll freely admit that I am out of my depth here but in the case of:
./IO/XMLParser/vtkXMLDataParser.cxx
./IO/XML/vtkXMLWriter.cxx
To me, it seems that std::unique_ptr would be the replacement.

In the case of:
./Common/DataModel/vtkDispatcher_Private.h
I'm not so sure. Especially since a swap seems to occur in line 309:
 Functor& operator=(const Functor& rhs)

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?

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)?

Regards
   Andrew


-- 
___________________________________________
Andrew J. P. Maclean

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


More information about the vtk-developers mailing list