template<typename T>
class pw::SharedPtr< T >
A std::shared_ptr<T>
-like type that integrates with pw::Allocator
.
This is a RAII smart pointer that deallocates any memory it points to when every pointer to the same object has gone out of scope.
Notable differences from std::shared_ptr<T>
include:
- It cannot be constructed from a
T*
. Use Allocator::MakeShared<T>(...)
instead.
- Aliasing constructors are not supported to encourage memory safety.
- Constructing a
SharedPtr
from a UniquePtr
takes an lvalue-reference, and is fallible..
- Template Parameters
-
T | The type being pointed to. This may be an array type, e.g. pw::SharedPtr<T[]> . |
|
| ~SharedPtr () |
| Releases any currently-held value.
|
|
constexpr | SharedPtr () noexcept=default |
|
constexpr | SharedPtr (std::nullptr_t) noexcept |
|
constexpr | SharedPtr (const SharedPtr &other) noexcept |
| Copy-constructs a SharedPtr<T> from a SharedPtr<T> .
|
|
template<typename U , typename = std::enable_if_t<std::is_assignable_v<T*&, U*>>> |
constexpr | SharedPtr (const SharedPtr< U > &other) noexcept |
|
template<typename U , typename = std::enable_if_t<std::is_assignable_v<T*&, U*>>> |
| SharedPtr (SharedPtr< U > &&other) noexcept |
|
| SharedPtr (UniquePtr< T > &owned) noexcept |
|
constexpr SharedPtr & | operator= (const SharedPtr &other) noexcept |
|
template<typename U , typename = std::enable_if_t<std::is_assignable_v<T*&, U*>>> |
constexpr SharedPtr & | operator= (const SharedPtr< U > &other) noexcept |
|
template<typename U , typename = std::enable_if_t<std::is_assignable_v<T*&, U*>>> |
SharedPtr & | operator= (SharedPtr< U > &&other) noexcept |
|
SharedPtr & | operator= (std::nullptr_t) noexcept |
|
template<typename U , typename = std::enable_if_t<std::is_assignable_v<T*&, U*>>> |
constexpr | operator const SharedPtr< U > & () const |
|
size_t | size () const |
|
int32_t | use_count () const |
|
void | reset () noexcept |
|
void | swap (SharedPtr &other) noexcept |
| Swaps the managed pointer and deallocator of this and another object.
|
|
template<typename PtrType > |
bool | owner_before (const PtrType &other) const noexcept |
|
template<typename... Args> |
SharedPtr< T > | Create (Allocator *allocator, Args &&... args) |
|
template<typename U , typename > |
constexpr SharedPtr< T > & | operator= (const SharedPtr< U > &other) noexcept |
|
template<typename U , typename > |
SharedPtr< T > & | operator= (SharedPtr< U > &&other) noexcept |
|
|
class | Allocator |
|
template<typename > |
class | WeakPtr |
|
template<MultiBufProperty... > |
class | BasicMultiBuf |
|
constexpr bool | operator== (const SharedPtr &lhs, std::nullptr_t) |
|
constexpr bool | operator== (std::nullptr_t, const SharedPtr &rhs) |
|
constexpr bool | operator== (const SharedPtr &lhs, const SharedPtr &rhs) |
|
constexpr bool | operator!= (const SharedPtr &lhs, std::nullptr_t) |
|
constexpr bool | operator!= (std::nullptr_t, const SharedPtr &rhs) |
|
constexpr bool | operator!= (const SharedPtr &lhs, const SharedPtr &rhs) |
|
template<typename T >
template<typename U , typename = std::enable_if_t<std::is_assignable_v<T*&, U*>>>
Move-constructs a SharedPtr<T>
from a SharedPtr<U>
.
This allows not only pure move construction where T == U
, but also converting construction where T
is a base class of U
, like SharedPtr<Base> base(deallocator.MakeShared<Child>());
.
template<typename T >
template<typename U , typename = std::enable_if_t<std::is_assignable_v<T*&, U*>>>
Copy-assigns a SharedPtr<T>
from a SharedPtr<U>
.
This operation releases the value currently stored in this
.
This allows not only pure copy assignment where T == U
, but also converting assignment where T
is a base class of U
.
template<typename T >
template<typename U , typename = std::enable_if_t<std::is_assignable_v<T*&, U*>>>
Move-assigns a SharedPtr<T>
from a SharedPtr<U>
.
This operation releases the value currently stored in this
.
This allows not only pure move assignment where T == U
, but also converting assignment where T
is a base class of U
.