Pigweed
C/C++ API Reference
|
Public Types | |
using | pointer = typename Base::element_type * |
using | element_type = typename Base::element_type |
Public Member Functions | |
constexpr | UniquePtr () noexcept |
constexpr | UniquePtr (std::nullptr_t) noexcept |
template<typename U > | |
UniquePtr (UniquePtr< U > &&other) noexcept | |
~UniquePtr () | |
Frees any currently-held value. | |
template<typename U > | |
UniquePtr & | operator= (UniquePtr< U > &&other) noexcept |
UniquePtr & | operator= (std::nullptr_t) noexcept |
size_t | size () const |
Deallocator * | deallocator () const |
Returns a pointer to the object that can destroy the value. | |
element_type * | Release () noexcept |
void | Reset () noexcept |
void | Swap (UniquePtr &other) |
Swaps the managed pointer and deallocator of this and another object. | |
template<typename U > | |
UniquePtr< T > & | operator= (UniquePtr< U > &&other) noexcept |
UniquePtr (element_type *value, Deallocator &deallocator) | |
UniquePtr (element_type *value, size_t size, Deallocator &deallocator) | |
Friends | |
class | Deallocator |
TODO(b/326509341): Remove when downstream consumers migrate. | |
A std::unique_ptr<T>
-like type that integrates with pw::Deallocator
.
This is a RAII smart pointer that deallocates any memory it points to when it goes out of scope.
Its most notable difference from std::unique_ptr<T>
is that it cannot be constructed from a T*
. Use Allocator::MakeUnique<T>(...)
instead.
T | The type being pointed to. This may be an array type, e.g. pw::UniquePtr<T[]> . |
TODO(b/399441816): This class should be marked final, but at least one downstream has extended it. Resolve and mark final.
|
inlineconstexprnoexcept |
Creates an empty (nullptr
) instance.
NOTE: Instances of this type are most commonly constructed using Allocator::MakeUnique
.
|
inlineconstexprnoexcept |
Creates an empty (nullptr
) instance.
NOTE: Instances of this type are most commonly constructed using Allocator::MakeUnique
.
|
inline |
Constructs a UniquePtr
from an already-allocated value.
The deallocator MUST be able to deallocate the given value
. Typically, this implies it is the same object that allocated the value.
This constructor "adopts" the value, that is, it assumes responsibility for its lifetime. Callers should not access the value directly after this call, and MUST not deallocate the value directly or pass it to another managed pointer.
NOTE: Instances of this type are most commonly constructed using MakeUnique
. Prefer that method when possible.
|
inlinenoexcept |
|
noexcept |
|
noexcept |
|
noexcept |
Releases a value from the UniquePtr
without destructing or deallocating it.
After this call, the object will have an "empty" (nullptr
) value.
|
noexcept |
Destroys and deallocates any currently-held value.
After this function returns, this UniquePtr
will be in an "empty" (nullptr
) state until a new value is assigned.
|
inline |
Returns the number of elements allocated.
This will fail to compile if it is called on a non-array type UniquePtr.