stlab.adobe.com Adobe Systems Incorporated

auto_ptr< X, Traits > Class Template Reference
[Memory]

The adobe::auto_ptr<> template adds a number of extensions to std::auto_ptr<>. More...

#include <memory.hpp>

List of all members.

Classes

struct  clear_type
struct  error_on_const_auto_type< auto_ptr< Y, typename traits_type::template rebind< Y * >::other > const >

Public Types

typedef traits_type::element_type element_type
typedef traits_type::pointer_type pointer_type
typedef Traits traits_type

Public Member Functions

 auto_ptr (pointer_type p=0) throw ()
 auto_ptr (auto_ptr &) throw ()
template<typename Y >
 auto_ptr (std::auto_ptr< Y > r) throw ()
template<typename Y >
 auto_ptr (const auto_ptr< Y, typename traits_type::template rebind< Y * >::other > &) throw ()
 auto_ptr (std::auto_ptr< X > r) throw ()
 operator std::auto_ptr< X > () throw ()
element_typeoperator* () const throw ()
pointer_type operator-> () const throw ()
auto_ptroperator= (const clear_type *) throw ()
template<typename Y >
auto_ptroperator= (auto_ptr< Y, typename traits_type::template rebind< Y * >::other >) throw ()
template<typename Y >
auto_ptroperator= (std::auto_ptr< Y >) throw ()
auto_ptroperator= (auto_ptr &) throw ()
auto_ptroperator= (std::auto_ptr< X >) throw ()
element_typeoperator[] (std::size_t index) const throw ()

Detailed Description

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
    • allows for per-instance state.
    • would allow for use with boost::function.
  • 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

Definition at line 398 of file memory.hpp.


Member Typedef Documentation

typedef traits_type::element_type element_type

Reimplemented from auto_resource< X *, Traits >.

Definition at line 405 of file memory.hpp.

typedef traits_type::pointer_type pointer_type

Reimplemented from auto_resource< X *, Traits >.

Definition at line 406 of file memory.hpp.

typedef Traits traits_type

Reimplemented from auto_resource< X *, Traits >.

Definition at line 404 of file memory.hpp.


Constructor & Destructor Documentation

auto_ptr ( pointer_type  p = 0 ) throw () [explicit]

Definition at line 529 of file memory.hpp.

auto_ptr ( auto_ptr< X, Traits > &  r ) throw ()

Definition at line 534 of file memory.hpp.

auto_ptr ( const auto_ptr< Y, typename traits_type::template rebind< Y * >::other > &  r ) throw ()

Definition at line 540 of file memory.hpp.

auto_ptr ( std::auto_ptr< X >  r ) throw ()

Definition at line 572 of file memory.hpp.

auto_ptr ( std::auto_ptr< Y >  r ) throw ()

Definition at line 578 of file memory.hpp.


Member Function Documentation

operator std::auto_ptr< X > (  ) throw ()

Definition at line 426 of file memory.hpp.

auto_ptr< X, Traits >::element_type & operator* (  ) const throw ()

Definition at line 601 of file memory.hpp.

auto_ptr< X, Traits >::pointer_type operator-> (  ) const throw ()

Definition at line 608 of file memory.hpp.

auto_ptr< X, Traits > & operator= ( auto_ptr< X, Traits > &  r ) throw ()

Definition at line 545 of file memory.hpp.

auto_ptr< X, Traits > & operator= ( std::auto_ptr< X >  r ) throw ()

Definition at line 583 of file memory.hpp.

auto_ptr< X, Traits > & operator= ( std::auto_ptr< Y >  r ) throw ()

Definition at line 591 of file memory.hpp.

auto_ptr< X, Traits > & operator= ( auto_ptr< Y, typename traits_type::template rebind< Y * >::other >  r ) throw ()

Definition at line 553 of file memory.hpp.

auto_ptr< X, Traits > & operator= ( const clear_type *   ) throw ()

Definition at line 563 of file memory.hpp.

auto_ptr< X, Traits >::element_type & operator[] ( std::size_t  index ) const throw ()

Definition at line 615 of file memory.hpp.

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google