A unique pointer is an object that owns another object and manages that other object through a pointer. More...
#include <unique_ptr.hpp>
Public Types | |
typedef D | deleter_type |
Public Member Functions | |
typedef | BOOST_MOVE_SEEDOC (pointer_type_obtainer::type) pointer |
If the type remove_reference<D>::type::pointer exists, then it shall be a synonym for remove_reference<D>::type::pointer . More... | |
typedef | BOOST_MOVE_SEEDOC (bmupmu::remove_extent< T >::type) element_type |
If T is an array type, then element_type is equal to T. More... | |
BOOST_CONSTEXPR | unique_ptr () BOOST_NOEXCEPT |
Requires: D shall satisfy the requirements of DefaultConstructible, and that construction shall not throw an exception. More... | |
BOOST_CONSTEXPR | unique_ptr (BOOST_MOVE_DOC0PTR(bmupd::nullptr_type)) BOOST_NOEXCEPT |
Effects: Same as unique_ptr() (default constructor). More... | |
template<class Pointer > | |
unique_ptr (Pointer p) BOOST_NOEXCEPT | |
Requires: D shall satisfy the requirements of DefaultConstructible, and that construction shall not throw an exception. More... | |
template<class Pointer > | |
unique_ptr (Pointer p, BOOST_MOVE_SEEDOC(deleter_arg_type1) d1) BOOST_NOEXCEPT | |
The signature of this constructor depends upon whether D is a reference type. More... | |
unique_ptr (BOOST_MOVE_DOC0PTR(bmupd::nullptr_type), BOOST_MOVE_SEEDOC(deleter_arg_type1) d1) BOOST_NOEXCEPT | |
Effects: Same effects as template<class Pointer> unique_ptr(Pointer p, deleter_arg_type1 d1) and additionally get() == nullptr More... | |
template<class Pointer > | |
unique_ptr (Pointer p, BOOST_MOVE_SEEDOC(deleter_arg_type2) d2) BOOST_NOEXCEPT | |
The signature of this constructor depends upon whether D is a reference type. More... | |
unique_ptr (BOOST_MOVE_DOC0PTR(bmupd::nullptr_type), BOOST_MOVE_SEEDOC(deleter_arg_type2) d2) BOOST_NOEXCEPT | |
Effects: Same effects as template<class Pointer> unique_ptr(Pointer p, deleter_arg_type2 d2) and additionally get() == nullptr More... | |
unique_ptr (BOOST_RV_REF(unique_ptr) u) BOOST_NOEXCEPT | |
Requires: If D is not a reference type, D shall satisfy the requirements of MoveConstructible. More... | |
template<class U , class E > | |
unique_ptr (BOOST_RV_REF_BEG unique_ptr< U, E > BOOST_RV_REF_END u) BOOST_NOEXCEPT | |
Requires: If E is not a reference type, construction of the deleter from an rvalue of type E shall be well formed and shall not throw an exception. More... | |
~unique_ptr () | |
Requires: The expression get_deleter()(get()) shall be well formed, shall have well-defined behavior, and shall not throw exceptions. More... | |
unique_ptr & | operator= (BOOST_RV_REF(unique_ptr) u) BOOST_NOEXCEPT |
Requires: If D is not a reference type, D shall satisfy the requirements of MoveAssignable and assignment of the deleter from an rvalue of type D shall not throw an exception. More... | |
A unique pointer is an object that owns another object and manages that other object through a pointer.
More precisely, a unique pointer is an object u that stores a pointer to a second object p and will dispose of p when u is itself destroyed (e.g., when leaving block scope). In this context, u is said to own p.
The mechanism by which u disposes of p is known as p's associated deleter, a function object whose correct invocation results in p's appropriate disposition (typically its deletion).
Let the notation u.p denote the pointer stored by u, and let u.d denote the associated deleter. Upon request, u can reset (replace) u.p and u.d with another pointer and deleter, but must properly dispose of its owned object via the associated deleter before such replacement is considered completed.
Additionally, u can, upon request, transfer ownership to another unique pointer u2. Upon completion of such a transfer, the following postconditions hold:
As in the case of a reset, u2 must properly dispose of its pre-transfer owned object via the pre-transfer associated deleter before the ownership transfer is considered complete.
Each object of a type U instantiated from the unique_ptr template specified in this subclause has the strict ownership semantics, specified above, of a unique pointer. In partial satisfaction of these semantics, each such U is MoveConstructible and MoveAssignable, but is not CopyConstructible nor CopyAssignable. The template parameter T of unique_ptr may be an incomplete type.
The uses of unique_ptr include providing exception safety for dynamically allocated memory, passing ownership of dynamically allocated memory to a function, and returning dynamically allocated memory from a function.
If T is an array type (e.g. unique_ptr<MyType[]>) the interface is slightly altered:
operator*
and operator->
are not provided.operator[]
is provided.T | Provides the type of the stored pointer. |
D | The deleter type:
|
typedef D boost::movelib::unique_ptr< T, D >::deleter_type |
|
inline |
Requires: D shall satisfy the requirements of DefaultConstructible, and that construction shall not throw an exception.
Effects: Constructs a unique_ptr object that owns nothing, value-initializing the stored pointer and the stored deleter.
Postconditions: get() == nullptr
. get_deleter()
returns a reference to the stored deleter.
Remarks: If this constructor is instantiated with a pointer type or reference type for the template argument D, the program is ill-formed.
References boost::BOOST_STATIC_ASSERT(), and boost::program_options::value().
|
inline |
Effects: Same as unique_ptr()
(default constructor).
References boost::BOOST_STATIC_ASSERT(), and boost::program_options::value().
|
inlineexplicit |
Requires: D shall satisfy the requirements of DefaultConstructible, and that construction shall not throw an exception.
Effects: Constructs a unique_ptr which owns p, initializing the stored pointer with p and value initializing the stored deleter.
Postconditions: get() == p
. get_deleter()
returns a reference to the stored deleter.
Remarks: If this constructor is instantiated with a pointer type or reference type for the template argument D, the program is ill-formed. This constructor shall not participate in overload resolution unless:
References boost::BOOST_STATIC_ASSERT(), and boost::program_options::value().
|
inline |
The signature of this constructor depends upon whether D is a reference type.
unique_ptr(pointer p, const A& d)
.unique_ptr(pointer p, A& d)
.unique_ptr(pointer p, const A& d)
.Requires: Either
Effects: Constructs a unique_ptr object which owns p, initializing the stored pointer with p and initializing the deleter as described above.
Postconditions: get() == p
. get_deleter()
returns a reference to the stored deleter. If D is a reference type then get_deleter()
returns a reference to the lvalue d.
Remarks: This constructor shall not participate in overload resolution unless:
References boost::BOOST_STATIC_ASSERT().
|
inline |
Effects: Same effects as template<class Pointer> unique_ptr(Pointer p, deleter_arg_type1 d1)
and additionally get() == nullptr
|
inline |
The signature of this constructor depends upon whether D is a reference type.
unique_ptr(pointer p, A&& d)
.unique_ptr(pointer p, A&& d)
.unique_ptr(pointer p, const A&& d)
.Requires: Either
Effects: Constructs a unique_ptr object which owns p, initializing the stored pointer with p and initializing the deleter as described above.
Postconditions: get() == p
. get_deleter()
returns a reference to the stored deleter. If D is a reference type then get_deleter()
returns a reference to the lvalue d.
Remarks: This constructor shall not participate in overload resolution unless:
References boost::BOOST_STATIC_ASSERT().
|
inline |
Effects: Same effects as template<class Pointer> unique_ptr(Pointer p, deleter_arg_type2 d2)
and additionally get() == nullptr
|
inline |
Requires: If D is not a reference type, D shall satisfy the requirements of MoveConstructible.
Construction of the deleter from an rvalue of type D shall not throw an exception.
Effects: Constructs a unique_ptr by transferring ownership from u to *this. If D is a reference type, this deleter is copy constructed from u's deleter; otherwise, this deleter is move constructed from u's deleter.
Postconditions: get()
yields the value u.get() yielded before the construction. get_deleter()
returns a reference to the stored deleter that was constructed from u.get_deleter(). If D is a reference type then get_deleter()
and u.get_deleter()
both reference the same lvalue deleter.
|
inline |
Requires: If E is not a reference type, construction of the deleter from an rvalue of type E shall be well formed and shall not throw an exception.
Otherwise, E is a reference type and construction of the deleter from an lvalue of type E shall be well formed and shall not throw an exception.
Remarks: This constructor shall not participate in overload resolution unless:
unique_ptr<U, E>::pointer
is implicitly convertible to pointer,Effects: Constructs a unique_ptr by transferring ownership from u to *this. If E is a reference type, this deleter is copy constructed from u's deleter; otherwise, this deleter is move constructed from u's deleter.
Postconditions: get()
yields the value u.get()
yielded before the construction. get_deleter()
returns a reference to the stored deleter that was constructed from u.get_deleter()
.
References boost::BOOST_STATIC_ASSERT().
|
inline |
Requires: The expression get_deleter()(get())
shall be well formed, shall have well-defined behavior, and shall not throw exceptions.
Effects: If get() == nullpt1r
there are no effects. Otherwise get_deleter()(get())
.
Note: The use of default_delete requires T to be a complete type
References boost::move_upd::unique_ptr_data< P, D, bool >::deleter(), and boost::move_upd::unique_ptr_data< P, D, bool >::m_p.
typedef boost::movelib::unique_ptr< T, D >::BOOST_MOVE_SEEDOC | ( | pointer_type_obtainer::type | ) |
If the type remove_reference<D>::type::pointer
exists, then it shall be a synonym for remove_reference<D>::type::pointer
.
Otherwise it shall be a synonym for T*.
typedef boost::movelib::unique_ptr< T, D >::BOOST_MOVE_SEEDOC | ( | bmupmu::remove_extent< T >::type | ) |
If T is an array type, then element_type is equal to T.
Otherwise, if T is a type in the form U[], element_type is equal to U.
|
inline |
Requires: If D is not a reference type, D shall satisfy the requirements of MoveAssignable and assignment of the deleter from an rvalue of type D shall not throw an exception.
Otherwise, D is a reference type; remove_reference<D>::type
shall satisfy the CopyAssignable requirements and assignment of the deleter from an lvalue of type D shall not throw an exception.
Effects: Transfers ownership from u to *this as if by calling reset(u.release())
followed by get_deleter() = std::forward<D>(u.get_deleter())
.
Returns: *this.
References boost::move_upd::unique_ptr_data< P, D, bool >::deleter().