Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a replacement for auto_ptr that can be used with boost ptr_map in c++11

Tags:

c++

c++11

boost

In c++11 auto_ptr is deprecated and replaced with the more sensible unique_ptr. Alas if you use boost::ptr_map the auto_ptr fulfilled a very handy use:

std::auto_ptr<Layer> pLayer(new Layer());
mRawLayerPtrMap.insert(layerName,pLayer);

Is there a possibility to use something similar with c++11. I know that

Layer* pLayer = new Layer();
mFusedLayers.insert(fusedLayerName,pLayer);

works but the auto_ptr had it's merits in some more complicated scenarios. Is there a replacement that works with C++11 ?

like image 882
Martin Avatar asked Feb 20 '23 13:02

Martin


1 Answers

How about

std::unique_ptr<Layer> pLayer(new Layer());
mFusedLayers.insert(fusedLayerName,pLayer.release());
like image 182
Ben Voigt Avatar answered Feb 25 '23 01:02

Ben Voigt