Type: recommended
Title: + class o3tl::heap_ptr<>
Posted by: [EMAIL PROTECTED]
Affected: o3tl
Effective from: CWS np-1
*Summary*
--------
+ template <class T> class heap_ptr;
Defined types:
+ typedef T element_type;
+ typedef heap_ptr<T> self;
Public members:
+ heap_ptr( T * pass_heapObject = 0 );
+ ~heap_ptr();
+ self & operator=(T * pass_heapObject );
+ const T & operator*() const;
+ T & operator*();
+ const T * operator->() const;
+ T * operator->();
+ void reset(T * pass_heapObject );
+ T * release();
+ void swap(self & io_other );
+ bool is() const;
+ const T * get() const;
+ T * get();
*Description*
-------------
heap_ptr<> owns an object on the heap, which will be automatically
deleted, when the destructor is called.
It is const-transitive and non-copyable.
Where Recommended:
Should replace plain pointers, when those point to heap objects that
are clearly owned by "this", or when they are to be deleted within the
current block.
Applicability:
heap_ptr<> should be used for class members on the heap.
One cannot forget to delete them in the destructor.
Constness will be transfered from the owning instance.
heap_ptr<> is one possible smart pointer to be used in function bodies
to ensure exception safety..
Special Characteristics:
heap_ptr<> transfers constness from the owning object to
the pointed to object. Such it behaves like if *get() would be
a normal member of the owning object, not a pointer member.
This is preferable to the normal pointer behaviour, because
if an object is owned by another one, it is normally part of
its state.
heap_ptr<> provides a release() function.
heap_ptr is non copyable. Classes with heap_ptr memebers will
automatically be non copyable, if they do not redefine the copy
functions themselves.
Incomplete Types:
heap_ptr<T> also works with incomplete types. One only needs to write
class T; but need not include <T>.hxx.
If you use heap_ptr<> with an incomplete type, the owning class
needs to define a non-inline destructor, else the compiler will
complain.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]