Auto ptr

auto_ptr is a class template that was available in previous versions of the C++ standard library (declared in the codice_1 header file), which provides some basic RAII features for C++ raw pointers. It has been replaced by the unique_ptr class. 
The codice_2 template class describes an object that stores a pointer to a single allocated object that ensures that the object to which it points gets destroyed automatically when control leaves a scope.
The C++11 standard made codice_2 deprecated, replacing it with the codice_4 class template. codice_2 was fully removed in C++17.
For shared ownership, the codice_6 template class can be used. codice_6 was defined in C++11 and is also available in the Boost library for use with previous C++ versions. 
Declaration.
The codice_2 class is declared in ISO/IEC 14882, section 20.4.5 as:
namespace std {
 template <class Y> struct auto_ptr_ref {};
 template <class X>
 class auto_ptr {
 public:
 typedef X element_type;
 // 20.4.5.1 construct/copy/destroy:
 explicit auto_ptr(X* p =0) throw();
 auto_ptr(auto_ptr&) throw();
 template <class Y> auto_ptr(auto_ptr<Y>&) throw();
 auto_ptr& operator=(auto_ptr&) throw();
 template <class Y> auto_ptr& operator=(auto_ptr<Y>&) throw();
 auto_ptr& operator=(auto_ptr_ref<X>) throw();
 ~auto_ptr() throw();
 // 20.4.5.2 members:
 X& operator*() const throw();
 X* operator->() const throw();
 X* get() const throw();
 X* release() throw();
 void reset(X* p =0) throw();
 // 20.4.5.3 conversions:
 auto_ptr(auto_ptr_ref<X>) throw();
 template <class Y> operator auto_ptr_ref<Y>() throw();
 template <class Y> operator auto_ptr<Y>() throw();
Semantics.
The codice_2 has semantics of strict ownership, meaning that the codice_2 instance is the sole entity responsible for the object's lifetime. If an codice_2 is copied, the source loses the reference. For example:
using namespace std;
int main(int argc, char **argv)
 int *i = new int;
 auto_ptr<int> x(i);
 auto_ptr<int> y;
 y = x;
 cout « x.get() « endl; // Print NULL
 cout « y.get() « endl; // Print non-NULL address i
 return 0;
This code will print a NULL address for the first codice_2 object and some non-NULL address for the second, showing that the source object lost the reference during the assignment (codice_13). The raw pointer codice_14 in the example should not be deleted, as it will be deleted by the codice_2 that owns the reference. In fact, codice_16 could be passed directly into codice_17, eliminating the need for codice_14.
Notice that the object pointed by an codice_2 is destroyed using codice_20; this means that you should only use codice_2 for pointers obtained with codice_22. This excludes pointers returned by codice_23, and pointers to arrays (because arrays are allocated by codice_24 and must be deallocated by codice_25).
Because of its copy semantics, codice_2 may not be used in STL containers that may perform element copies in their operations.