Simplifying code and achieving exception safety using unique_ptr -- Marshall Clow

This article talks about how modern C++ unique_ptr tool can be used to achieve exception safety.

Simplifying code and achieving exception safety using unique_ptr

by Marshall Clow

From the article:

The general pattern for this is:
  unique_ptr<T> holder(new T{/* params */});
  // set up some stuff that uses holder.get()
  holder.release();

Add a Comment

Comments are closed.

Comments (2)

0 0

Rob G said on Mar 12, 2015 03:32 AM:

The general pattern is good, but in the article he directly uses a class that is internal to LibC++ "__allocator_destructor" in his own code. That is not something I'd consider good practice - non-portable and brittle.
0 0

marshall said on Mar 12, 2015 02:33 PM:

> in the article he directly uses a class that is internal to LibC++ "__allocator_destructor" in his own code

"My own code" in this case was libc++, so your concern (while valid) is misplaced.