20#include "pw_allocator/config.h"
21#include "pw_allocator/internal/managed_ptr.h"
22#include "pw_preprocessor/compiler.h"
40class UniquePtr :
public ::pw::allocator::internal::ManagedPtr<T> {
42 using Base = ::pw::allocator::internal::ManagedPtr<T>;
43 using Empty = ::pw::allocator::internal::Empty;
46 using pointer =
typename Base::element_type*;
47 using element_type =
typename Base::element_type;
54 if constexpr (std::is_array_v<T>) {
72 *
this = std::move(other);
97 static_assert(std::is_array_v<T>,
98 "size() cannot be called with a non-array type");
109 element_type*
Release() noexcept;
115 void Reset() noexcept;
149 template <
typename U>
150 void CopyFrom(
const UniquePtr<U>& other);
156 std::conditional_t<std::is_array_v<T>, size_t, Empty> size_;
167using UniquePtr = PW_ALLOCATOR_DEPRECATED ::pw::UniquePtr<T>;
190 element_type* value = Base::Release();
191 deallocator_ =
nullptr;
197 if (*
this ==
nullptr) {
200 if (!Base::HasCapability(deallocator_, allocator::kSkipsDestroy)) {
201 if constexpr (std::is_array_v<T>) {
202 Base::Destroy(size_);
208 Base::Deallocate(deallocator, Release());
214 if constexpr (std::is_array_v<T>) {
215 std::swap(size_, other.size_);
217 std::swap(deallocator_, other.deallocator_);
223 Base::CopyFrom(other);
225 deallocator_ = other.deallocator_;
Abstract interface for releasing memory.
Definition: deallocator.h:26
Definition: unique_ptr.h:40
UniquePtr(UniquePtr< U > &&other) noexcept
Definition: unique_ptr.h:71
element_type * Release() noexcept
Definition: unique_ptr.h:189
Deallocator * deallocator() const
Returns a pointer to the object that can destroy the value.
Definition: unique_ptr.h:103
void Reset() noexcept
Definition: unique_ptr.h:196
constexpr UniquePtr() noexcept
Definition: unique_ptr.h:53
size_t size() const
Definition: unique_ptr.h:96
UniquePtr & operator=(UniquePtr< U > &&other) noexcept
friend class Deallocator
TODO(b/326509341): Remove when downstream consumers migrate.
Definition: unique_ptr.h:122
~UniquePtr()
Frees any currently-held value.
Definition: unique_ptr.h:76
constexpr UniquePtr(std::nullptr_t) noexcept
Definition: unique_ptr.h:63
void Swap(UniquePtr &other)
Swaps the managed pointer and deallocator of this and another object.
Definition: unique_ptr.h:212
Provides basic helpers for reading and writing UTF-8 encoded strings.
Definition: alignment.h:27