make new SetLongevity impl more exception safety

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@359 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
syntheticpp 2005-11-13 14:32:03 +00:00
parent f10f61534c
commit a1b035fd15

View file

@ -24,6 +24,7 @@
#include <new>
#include <vector>
#include <list>
#include <memory>
#ifdef _MSC_VER
@ -138,19 +139,23 @@ namespace Loki
if(pTrackerArray==0)
pTrackerArray = new TrackerArray;
LifetimeTracker* p = new ConcreteLifetimeTracker<T, Destroyer>(
pDynObject, longevity, d);
// automatically delete the ConcreteLifetimeTracker object when a exception is thrown
std::auto_ptr<LifetimeTracker>
p( new ConcreteLifetimeTracker<T, Destroyer>(pDynObject, longevity, d) );
// Find correct position
TrackerArray::iterator pos = std::upper_bound(
pTrackerArray->begin(),
pTrackerArray->end(),
p,
p.get(),
LifetimeTracker::Compare);
// Insert a pointer to the object into the queue
pTrackerArray->insert(pos, p);
// Insert the pointer to the ConcreteLifetimeTracker object into the queue
pTrackerArray->insert(pos, p.get());
// nothing has thrown: don't delete the ConcreteLifetimeTracker object
p.release();
// Register a call to AtExitFn
std::atexit(Private::AtExitFn);
}