.TH "std::auto_ptr< _Tp >" 3cxx "Sat Aug 14 2021" "libstdc++" \" -*- nroff -*- .ad l .nh .SH NAME std::auto_ptr< _Tp > \- A simple smart pointer providing strict ownership semantics\&. .SH SYNOPSIS .br .PP .SS "Public Types" .in +1c .ti -1c .RI "typedef _Tp \fBelement_type\fP" .br .RI "The pointed-to type\&. " .in -1c .SS "Public Member Functions" .in +1c .ti -1c .RI "\fBauto_ptr\fP (\fBauto_ptr\fP &__a) throw ()" .br .RI "An auto_ptr can be constructed from another auto_ptr\&. " .ti -1c .RI "template \fBauto_ptr\fP (\fBauto_ptr\fP< _Tp1 > &__a) throw ()" .br .RI "An auto_ptr can be constructed from another auto_ptr\&. " .ti -1c .RI "\fBauto_ptr\fP (\fBauto_ptr_ref\fP< \fBelement_type\fP > __ref) throw ()" .br .RI "Automatic conversions\&. " .ti -1c .RI "\fBauto_ptr\fP (\fBelement_type\fP *__p=0) throw ()" .br .RI "An auto_ptr is usually constructed from a raw pointer\&. " .ti -1c .RI "\fB~auto_ptr\fP ()" .br .ti -1c .RI "\fBelement_type\fP * \fBget\fP () const throw ()" .br .RI "Bypassing the smart pointer\&. " .ti -1c .RI "template \fBoperator auto_ptr< _Tp1 >\fP () throw ()" .br .ti -1c .RI "template \fBoperator auto_ptr_ref< _Tp1 >\fP () throw ()" .br .ti -1c .RI "\fBelement_type\fP & \fBoperator*\fP () const throw ()" .br .RI "Smart pointer dereferencing\&. " .ti -1c .RI "\fBelement_type\fP * \fBoperator\->\fP () const throw ()" .br .RI "Smart pointer dereferencing\&. " .ti -1c .RI "\fBauto_ptr\fP & \fBoperator=\fP (\fBauto_ptr\fP &__a) throw ()" .br .RI "auto_ptr assignment operator\&. " .ti -1c .RI "template \fBauto_ptr\fP & \fBoperator=\fP (\fBauto_ptr\fP< _Tp1 > &__a) throw ()" .br .RI "auto_ptr assignment operator\&. " .ti -1c .RI "\fBauto_ptr\fP & \fBoperator=\fP (\fBauto_ptr_ref\fP< \fBelement_type\fP > __ref) throw ()" .br .ti -1c .RI "\fBelement_type\fP * \fBrelease\fP () throw ()" .br .RI "Bypassing the smart pointer\&. " .ti -1c .RI "void \fBreset\fP (\fBelement_type\fP *__p=0) throw ()" .br .RI "Forcibly deletes the managed object\&. " .in -1c .SH "Detailed Description" .PP .SS "template .br class std::auto_ptr< _Tp >" A simple smart pointer providing strict ownership semantics\&. The Standard says: .PP .nf An \fCauto_ptr\fP owns the object it holds a pointer to\&. Copying an \fCauto_ptr\fP copies the pointer and transfers ownership to the destination\&. If more than one \fCauto_ptr\fP owns the same object at the same time the behavior of the program is undefined\&. The uses of \fCauto_ptr\fP include providing temporary exception-safety for dynamically allocated memory, passing ownership of dynamically allocated memory to a function, and returning dynamically allocated memory from a function\&. \fCauto_ptr\fP does not meet the CopyConstructible and Assignable requirements for Standard Library \fCcontainer\fP elements and thus instantiating a Standard Library container with an \fCauto_ptr\fP results in undefined behavior\&. .fi .PP Quoted from [20\&.4\&.5]/3\&. .PP Good examples of what can and cannot be done with auto_ptr can be found in the libstdc++ testsuite\&. .PP _GLIBCXX_RESOLVE_LIB_DEFECTS 127\&. auto_ptr<> conversion issues These resolutions have all been incorporated\&. .PP Definition at line 89 of file auto_ptr\&.h\&. .SH "Member Typedef Documentation" .PP .SS "template typedef _Tp \fBstd::auto_ptr\fP< _Tp >::\fBelement_type\fP" .PP The pointed-to type\&. .PP Definition at line 96 of file auto_ptr\&.h\&. .SH "Constructor & Destructor Documentation" .PP .SS "template \fBstd::auto_ptr\fP< _Tp >::\fBauto_ptr\fP (\fBelement_type\fP * __p = \fC0\fP)\fC [inline]\fP, \fC [explicit]\fP" .PP An auto_ptr is usually constructed from a raw pointer\&. .PP \fBParameters\fP .RS 4 \fI__p\fP A pointer (defaults to NULL)\&. .RE .PP This object now \fIowns\fP the object pointed to by \fI__p\fP\&. .PP Definition at line 105 of file auto_ptr\&.h\&. .SS "template \fBstd::auto_ptr\fP< _Tp >::\fBauto_ptr\fP (\fBauto_ptr\fP< _Tp > & __a)\fC [inline]\fP" .PP An auto_ptr can be constructed from another auto_ptr\&. .PP \fBParameters\fP .RS 4 \fI__a\fP Another auto_ptr of the same type\&. .RE .PP This object now \fIowns\fP the object previously owned by \fI__a\fP, which has given up ownership\&. .PP Definition at line 114 of file auto_ptr\&.h\&. .SS "template template \fBstd::auto_ptr\fP< _Tp >::\fBauto_ptr\fP (\fBauto_ptr\fP< _Tp1 > & __a)\fC [inline]\fP" .PP An auto_ptr can be constructed from another auto_ptr\&. .PP \fBParameters\fP .RS 4 \fI__a\fP Another auto_ptr of a different but related type\&. .RE .PP A pointer-to-Tp1 must be convertible to a pointer-to-Tp/element_type\&. .PP This object now \fIowns\fP the object previously owned by \fI__a\fP, which has given up ownership\&. .PP Definition at line 127 of file auto_ptr\&.h\&. .SS "template \fBstd::auto_ptr\fP< _Tp >::~\fBauto_ptr\fP ()\fC [inline]\fP" When the auto_ptr goes out of scope, the object it owns is deleted\&. If it no longer owns anything (i\&.e\&., \fCget()\fP is \fCNULL\fP), then this has no effect\&. .PP The C++ standard says there is supposed to be an empty throw specification here, but omitting it is standard conforming\&. Its presence can be detected only if _Tp::~_Tp() throws, but this is prohibited\&. [17\&.4\&.3\&.6]/2 .PP Definition at line 172 of file auto_ptr\&.h\&. .SS "template \fBstd::auto_ptr\fP< _Tp >::\fBauto_ptr\fP (\fBauto_ptr_ref\fP< \fBelement_type\fP > __ref)\fC [inline]\fP" .PP Automatic conversions\&. These operations are supposed to convert an auto_ptr into and from an auto_ptr_ref automatically as needed\&. This would allow constructs such as .PP .nf auto_ptr func_returning_auto_ptr(\&.\&.\&.\&.\&.); \&.\&.\&. auto_ptr ptr = func_returning_auto_ptr(\&.\&.\&.\&.\&.); .fi .PP .PP But it doesn't work, and won't be fixed\&. For further details see http://cplusplus.github.io/LWG/lwg-closed.html#463 .PP Definition at line 266 of file auto_ptr\&.h\&. .SH "Member Function Documentation" .PP .SS "template \fBelement_type\fP* \fBstd::auto_ptr\fP< _Tp >::get (void) const\fC [inline]\fP" .PP Bypassing the smart pointer\&. .PP \fBReturns\fP .RS 4 The raw pointer being managed\&. .RE .PP You can get a copy of the pointer that this object owns, for situations such as passing to a function which only accepts a raw pointer\&. .PP \fBNote\fP .RS 4 This auto_ptr still owns the memory\&. .RE .PP .PP Definition at line 213 of file auto_ptr\&.h\&. .SS "template \fBelement_type\fP& \fBstd::auto_ptr\fP< _Tp >::operator* () const\fC [inline]\fP" .PP Smart pointer dereferencing\&. If this auto_ptr no longer owns anything, then this operation will crash\&. (For a smart pointer, \fIno longer owns anything\fP is the same as being a null pointer, and you know what happens when you dereference one of those\&.\&.\&.) .PP Definition at line 183 of file auto_ptr\&.h\&. .SS "template \fBelement_type\fP* \fBstd::auto_ptr\fP< _Tp >::operator\-> () const\fC [inline]\fP" .PP Smart pointer dereferencing\&. This returns the pointer itself, which the language then will automatically cause to be dereferenced\&. .PP Definition at line 196 of file auto_ptr\&.h\&. .SS "template \fBauto_ptr\fP& \fBstd::auto_ptr\fP< _Tp >::operator= (\fBauto_ptr\fP< _Tp > & __a)\fC [inline]\fP" .PP auto_ptr assignment operator\&. .PP \fBParameters\fP .RS 4 \fI__a\fP Another auto_ptr of the same type\&. .RE .PP This object now \fIowns\fP the object previously owned by \fI__a\fP, which has given up ownership\&. The object that this one \fIused\fP to own and track has been deleted\&. .PP Definition at line 138 of file auto_ptr\&.h\&. .PP References std::auto_ptr< _Tp >::reset()\&. .SS "template template \fBauto_ptr\fP& \fBstd::auto_ptr\fP< _Tp >::operator= (\fBauto_ptr\fP< _Tp1 > & __a)\fC [inline]\fP" .PP auto_ptr assignment operator\&. .PP \fBParameters\fP .RS 4 \fI__a\fP Another auto_ptr of a different but related type\&. .RE .PP A pointer-to-Tp1 must be convertible to a pointer-to-Tp/element_type\&. .PP This object now \fIowns\fP the object previously owned by \fI__a\fP, which has given up ownership\&. The object that this one \fIused\fP to own and track has been deleted\&. .PP Definition at line 156 of file auto_ptr\&.h\&. .PP References std::auto_ptr< _Tp >::reset()\&. .SS "template \fBelement_type\fP* \fBstd::auto_ptr\fP< _Tp >::release ()\fC [inline]\fP" .PP Bypassing the smart pointer\&. .PP \fBReturns\fP .RS 4 The raw pointer being managed\&. .RE .PP You can get a copy of the pointer that this object owns, for situations such as passing to a function which only accepts a raw pointer\&. .PP \fBNote\fP .RS 4 This auto_ptr no longer owns the memory\&. When this object goes out of scope, nothing will happen\&. .RE .PP .PP Definition at line 227 of file auto_ptr\&.h\&. .SS "template void \fBstd::auto_ptr\fP< _Tp >::reset (\fBelement_type\fP * __p = \fC0\fP)\fC [inline]\fP" .PP Forcibly deletes the managed object\&. .PP \fBParameters\fP .RS 4 \fI__p\fP A pointer (defaults to NULL)\&. .RE .PP This object now \fIowns\fP the object pointed to by \fI__p\fP\&. The previous object has been deleted\&. .PP Definition at line 242 of file auto_ptr\&.h\&. .PP Referenced by std::auto_ptr< _Tp >::operator=()\&. .SH "Author" .PP Generated automatically by Doxygen for libstdc++ from the source code\&.