20 General utilities library [utilities]
namespace std {
template<class T, class D = default_delete<T>> class unique_ptr {
public:
using pointer = see below;
using element_type = T;
using deleter_type = D;
constexpr unique_ptr() noexcept;
explicit unique_ptr(pointer p) noexcept;
unique_ptr(pointer p, see below d1) noexcept;
unique_ptr(pointer p, see below d2) noexcept;
unique_ptr(unique_ptr&& u) noexcept;
constexpr unique_ptr(nullptr_t) noexcept;
template<class U, class E>
unique_ptr(unique_ptr<U, E>&& u) noexcept;
~unique_ptr();
unique_ptr& operator=(unique_ptr&& u) noexcept;
template<class U, class E>
unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
unique_ptr& operator=(nullptr_t) noexcept;
add_lvalue_reference_t<T> operator*() const;
pointer operator->() const noexcept;
pointer get() const noexcept;
deleter_type& get_deleter() noexcept;
const deleter_type& get_deleter() const noexcept;
explicit operator bool() const noexcept;
pointer release() noexcept;
void reset(pointer p = pointer()) noexcept;
void swap(unique_ptr& u) noexcept;
unique_ptr(const unique_ptr&) = delete;
unique_ptr& operator=(const unique_ptr&) = delete;
};
}
The default type for the template parameter
D is
default_delete. A client-supplied template argument
D shall be a
function object type,
lvalue reference to function, or
lvalue reference to function object type
for which, given
a value
d of type
D and a value
ptr of type
unique_ptr<T, D>::pointer, the expression
d(ptr) is valid and has the effect of disposing of the
pointer as appropriate for that deleter
.If the deleter's type
D is not a reference type,
D shall meet
the
Cpp17Destructible requirements (Table
32)
.If the
qualified-id remove_reference_t<D>::pointer is valid and denotes a
type (
[temp.deduct]), then
unique_ptr<T,
D>::pointer shall be a synonym for
remove_reference_t<D>::pointer. Otherwise
unique_ptr<T, D>::pointer shall be a synonym for
element_type*. The type
unique_ptr<T,
D>::pointer shall
meet the
Cpp17NullablePointer requirements (Table
33)
.[
Example 1:
Given an allocator type
X (Table
36) and
letting
A be a synonym for
allocator_traits<X>, the types
A::pointer,
A::const_pointer,
A::void_pointer, and
A::const_void_pointer
may be used as
unique_ptr<T, D>::pointer. —
end example]