[asterisk-scf-dev] auto_ptr

Brent Eagles beagles at digium.com
Tue Nov 30 09:37:04 CST 2010


On Tue, Nov 30, 2010 at 07:45:23AM -0600, Simon Perreault wrote:
> On 2010-11-30 08:28, Kevin P. Fleming wrote:
> > Besides all of that... auto_ptr was deprecated for a reason. It's fairly 
> > easy to misuse, so I'd rather not see usage of it in our code if it can 
> > be avoided, since it could lead to others copying that usage and not 
> > understanding the subtleties of it.
> 
> Could it be possible to use auto_ptr for now and s/auto_ptr/unique_ptr/
> when C++0x arrives, or is the usage that much different?

Some cases would allow direct replacement, but there could be some
breakages. For example, you cannot simply "copy" unique_ptr's via copy
construction. In auto_ptr land, a copy is really a *move* and this has
been made explicit in unique_ptr.  However, these would be compile time
issues and not runtime bugs that would appear when you made the switch.

As Kevin pointed out, moving to unique_ptr ASAP has some advantages. Two
immediate ones that come to mind are:

- it prevents some misuses
- it is supposed to handle arrays properly (calls delete[]) 

Boost's unique_ptr is available for platforms that have compilers that
aren't up to speed with c++0x. In other words, if you can build Asterisk
SCF, you probably already have access to a unique_ptr implementation.

Cheers,

Brent



More information about the asterisk-scf-dev mailing list