template<typename X, class Traits = ptr_traits<X*>>
class adobe::auto_ptr< X, Traits >
Although std::auto_ptr<>
is a non-regular type, it has proven to be valueable especially when converting C or non-exception aware C++ to exception aware C++ code. It is also useful when dealing with C libraries (such as OS libraries) that by necisity return pointers.
However, std::auto_ptr<>
has a number of limitations that make use error prone, limit when it can be used, and make it's use more combursome than necessary.
The auto_ptr<>
includes the following not present in std::auto_ptr<>
:
- The inclusion of ptr_traits to support alternative delete functions.
- Proper support for array types.
- Support for assignment from function results.
- Safe bool casts.
- Assignment and construction from NULL.
Also, auto_resource<>
is provided for non-pointer and opaque pointer references.
Rationals:
Rational for not going with boost: scoped_ptr interface: The interface to boost:scoped_ptr is a constrained subset of auto_ptr with out any improvements. I'm not a fan of providing a whole new interface to prevent the user from performing some operations.
Rational for traits instead of policies:
- Advantages of policies
- Disadvanteages
- no real world examples to demonstrate the advantages.
- complicates implementation to properly handle exceptions from throwing when assigning policies.
- prohibits use of no-throw in declarations (may not be an actual disadvantage).
- would require more complex interface for constructors.
- would require swap be added to the interface to achieve a non-throwing swap and it is unclear how swap could be generally implemented.
In total I thought the advantages didn't warrant the effort. If someone come demonstrate a concrete instance where there would be a strong advantage I'd reconsider.
Differences between photoshop linear types and adobe:: types:
- traits_type replaces deallocator and provides custom null checks
- Safe bool casts.
- Assignment and construction from NULL.
- template based constructor, assignment, and conversion
linear_resource -> adobe::auto_resource
Definition at line 80 of file memory.hpp.