auto_destructor Class Template Reference
[Memory Library]

#include <stlsoft/memory/auto_destructor.hpp>

List of all members.


Detailed Description

template<typename T>
class stlsoft::auto_destructor< T >

This class acts as an automatic frame scope variable that manages heap-allocated object instances.

Parameters:
T The value type
A heap-allocated resource to be managed is placed into an instance of auto_destructor in its constructor, as in:
  {
    stlsoft::auto_destructor<MyClass>  adi(new MyClass(1, 2));

    . . .
  } // The MyClass instance is deleted here

The horrendous, and widely lamented, problems with std::auto_ptr are avoided by proscribing copy operations. Hence:

    stlsoft::auto_destructor<MyClass>  adi(new MyClass(1, 2));
    stlsoft::auto_destructor<MyClass>  adi2(adi); // Compile error!

But resources can be returned out of auto_destructor instances from functions by virtue of return_value_destructor, as in:

  stlsoft::return_value_destructor<MyClass> f(int i, int j)
  {
    stlsoft::auto_destructor<MyClass>  adi(new MyClass(i, j));

    . . .
  } // The MyClass instance is deleted here

  stlsoft::auto_destructor<MyClass>  adi2 = f(1, 2);

In this way, the resource is completely safely managed, without there being any unfortunate side-effects (as is the case with std::auto_ptr).

See also:
stlsoft::return_value_destructor
Examples:

by_library/memory/auto_destructor/auto_destructor.cpp.


Types

typedef T value_type
 The value type.
typedef auto_destructor< T > class_type
 The current parameterisation of the type.
typedef
return_value_destructor< T > 
return_value_type
 The return value type.

Public Member Functions

Construction
 auto_destructor (value_type *t)
 Constructs from the pointer to an instance whose lifetime will be managed.
 auto_destructor (proxy_type rhs)
 Proxy move constructor.
 ~auto_destructor () throw ()
 Destroys the managed instance.
Operations
value_typedetach ()
 Detaches the managed instance from the auto_destructor and returns a pointer to it to the caller.
Accessors
value_typeoperator-> ()
 Implicit conversion to pointer to the managed instance.
value_type const * operator-> () const
 Implicit conversion to pointer-to-const to the managed instance.
value_typeget_ptr () const
 Returns the pointer.
value_typeget () const
 Returns the pointer.

Member Typedef Documentation

typedef T value_type

The value type.

The current parameterisation of the type.

The return value type.


Constructor & Destructor Documentation

auto_destructor ( value_type t  )  [inline, explicit]

Constructs from the pointer to an instance whose lifetime will be managed.

auto_destructor ( proxy_type  rhs  )  [inline]

Proxy move constructor.

~auto_destructor (  )  throw () [inline]

Destroys the managed instance.


Member Function Documentation

value_type* detach (  )  [inline]

Detaches the managed instance from the auto_destructor and returns a pointer to it to the caller.

Note:
The caller becomes responsible for destroying the instance.

value_type* operator-> (  )  [inline]

Implicit conversion to pointer to the managed instance.

value_type const* operator-> (  )  const [inline]

Implicit conversion to pointer-to-const to the managed instance.

value_type* get_ptr (  )  const [inline]

Returns the pointer.

Deprecated:
This function will be removed in a future release. Users should instead invoke get()

value_type* get (  )  const [inline]

Returns the pointer.

Referenced by indirect_reverse_iterator::base().


The documentation for this class was generated from the following file:

Generated on Thu Jun 10 08:58:53 2010 for STLSoft by  doxygen 1.5.6