Pigweed
C/C++ API Reference
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Friends | List of all members
pw::SharedPtr< T > Class Template Referencefinal
Inheritance diagram for pw::SharedPtr< T >:

Public Types

using element_type = typename Base::element_type
 
using weak_type = WeakPtr< T >
 

Public Member Functions

 ~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 >
constexpr SharedPtr (const SharedPtr< U > &other) noexcept
 
template<typename U >
 SharedPtr (SharedPtr< U > &&other) noexcept
 
constexpr SharedPtroperator= (const SharedPtr &other) noexcept
 
template<typename U >
constexpr SharedPtroperator= (const SharedPtr< U > &other) noexcept
 
template<typename U >
SharedPtroperator= (SharedPtr< U > &&other) noexcept
 
SharedPtroperator= (std::nullptr_t) noexcept
 
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 >
constexpr SharedPtr< T > & operator= (const SharedPtr< U > &other) noexcept
 
template<typename U >
SharedPtr< T > & operator= (SharedPtr< U > &&other) noexcept
 

Friends

class Allocator
 
template<typename >
class WeakPtr
 
template<MultiBufProperty... >
class BasicMultiBuf
 

Detailed Description

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:

Template Parameters
TThe type being pointed to. This may be an array type, e.g. pw::SharedPtr<T[]>.

Constructor & Destructor Documentation

◆ SharedPtr() [1/4]

template<typename T >
constexpr pw::SharedPtr< T >::SharedPtr ( )
constexprdefaultnoexcept

Creates an empty (nullptr) instance.

NOTE: Instances of this type are most commonly constructed using Allocator::MakeShared.

◆ SharedPtr() [2/4]

template<typename T >
constexpr pw::SharedPtr< T >::SharedPtr ( std::nullptr_t  )
inlineconstexprnoexcept

Creates an empty (nullptr) instance.

NOTE: Instances of this type are most commonly constructed using Allocator::MakeShared.

◆ SharedPtr() [3/4]

template<typename T >
template<typename U >
constexpr pw::SharedPtr< T >::SharedPtr ( const SharedPtr< U > &  other)
inlineconstexprnoexcept

Copy-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.

◆ SharedPtr() [4/4]

template<typename T >
template<typename U >
pw::SharedPtr< T >::SharedPtr ( SharedPtr< U > &&  other)
inlinenoexcept

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>());.

Member Function Documentation

◆ operator=() [1/4]

template<typename T >
constexpr SharedPtr & pw::SharedPtr< T >::operator= ( const SharedPtr< T > &  other)
inlineconstexprnoexcept

Copy-assigns a SharedPtr<T> from a SharedPtr<T>.

This operation releases the value currently stored in this.

◆ operator=() [2/4]

template<typename T >
template<typename U >
constexpr SharedPtr & pw::SharedPtr< T >::operator= ( const SharedPtr< U > &  other)
constexprnoexcept

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.

◆ operator=() [3/4]

template<typename T >
template<typename U >
SharedPtr & pw::SharedPtr< T >::operator= ( SharedPtr< U > &&  other)
noexcept

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.

◆ operator=() [4/4]

template<typename T >
SharedPtr< T > & pw::SharedPtr< T >::operator= ( std::nullptr_t  )
noexcept

Sets this ManagedPtr to null, releasing any currently-held value.

After this function returns, this ManagedPtr will be in an "empty" (nullptr) state until a new value is assigned.

◆ owner_before()

template<typename T >
template<typename PtrType >
bool pw::SharedPtr< T >::owner_before ( const PtrType &  other) const
inlinenoexcept

Checks whether this precedes other based on an ordering of their control blocks.

◆ reset()

template<typename T >
void pw::SharedPtr< T >::reset
noexcept

Resets this object to an empty state.

If this was the last shared pointer to the associated object, it is destroyed. If this is the last shared or weak pointer associated with the control block, it is deallocated.

◆ size()

template<typename T >
size_t pw::SharedPtr< T >::size ( ) const
inline

Returns the number of elements allocated.

This will fail to compile if it is called on a non-array type SharedPtr.

◆ use_count()

template<typename T >
int32_t pw::SharedPtr< T >::use_count ( ) const
inline

Returns the number of shared pointers to the associated object, or 0 if this object is empty.


The documentation for this class was generated from the following file: