24namespace allocator::internal {
32 using Capability = ::pw::allocator::Capability;
34 static bool HasCapability(
Deallocator* deallocator, Capability capability);
35 static void Deallocate(
Deallocator* deallocator,
void* ptr);
55 constexpr UniquePtr() : value_(nullptr), deallocator_(nullptr) {}
70 : value_(other.value_), deallocator_(other.deallocator_) {
72 std::is_assignable_v<T*&, U*>,
73 "Attempted to construct a UniquePtr<T> from a UniquePtr<U> where "
74 "U* is not assignable to T*.");
95 static_assert(std::is_assignable_v<T*&, U*>,
96 "Attempted to assign a UniquePtr<U> to a UniquePtr<T> where "
97 "U* is not assignable to T*.");
99 value_ = other.value_;
100 deallocator_ = other.deallocator_;
128 deallocator_ =
nullptr;
137 if (value_ ==
nullptr) {
140 if (!Base::HasCapability(deallocator_, Capability::kSkipsDestroy)) {
141 std::destroy_at(value_);
143 Base::Deallocate(deallocator_, value_);
151 explicit operator bool()
const =
delete;
154 bool operator==(std::nullptr_t)
const {
return value_ ==
nullptr; }
158 bool operator!=(std::nullptr_t)
const {
return value_ !=
nullptr; }
161 T*
get() {
return value_; }
163 const T*
get()
const {
return value_; }
170 const T*
operator->()
const {
return value_; }
177 const T&
operator*()
const {
return *value_; }
192 template <
typename U>
195 class PrivateConstructorType {};
196 static constexpr PrivateConstructorType kPrivateConstructor{};
Abstract interface for releasing memory.
Definition: deallocator.h:26
Definition: unique_ptr.h:47
bool operator==(std::nullptr_t) const
Returns whether this UniquePtr is in an "empty" (nullptr) state.
Definition: unique_ptr.h:154
UniquePtr(UniquePtr< U > &&other) noexcept
Definition: unique_ptr.h:69
friend class UniquePtr
Definition: unique_ptr.h:193
bool operator!=(std::nullptr_t) const
Definition: unique_ptr.h:158
constexpr UniquePtr()
Definition: unique_ptr.h:55
T * get()
Returns the underlying (possibly null) pointer.
Definition: unique_ptr.h:161
Deallocator * deallocator() const
Returns a pointer to the object that can destroy the value.
Definition: unique_ptr.h:119
constexpr UniquePtr(std::nullptr_t)
Definition: unique_ptr.h:61
UniquePtr & operator=(std::nullptr_t)
Definition: unique_ptr.h:110
void Reset()
Definition: unique_ptr.h:136
UniquePtr & operator=(UniquePtr< U > &&other) noexcept
Definition: unique_ptr.h:94
const T * get() const
Returns the underlying (possibly null) pointer.
Definition: unique_ptr.h:163
T * operator->()
Definition: unique_ptr.h:169
T & operator*()
Definition: unique_ptr.h:176
friend class Deallocator
TODO(b/326509341): Remove when downstream consumers migrate.
Definition: unique_ptr.h:211
UniquePtr(PrivateConstructorType, T *value, Deallocator *deallocator)
Definition: unique_ptr.h:206
~UniquePtr()
Destructs and deallocates any currently-held value.
Definition: unique_ptr.h:116
T * Release()
Definition: unique_ptr.h:125
Definition: unique_ptr.h:30
Provides basic helpers for reading and writing UTF-8 encoded strings.
Definition: alignment.h:27