UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TSharedPtr< ObjectType, InMode > Class Template Reference

#include <SharedPointer.h>

Public Types

using ElementType = ObjectType
 
using IntrusiveUnsetOptionalStateType = TSharedPtr
 

Public Member Functions

 TSharedPtr (SharedPointerInternals::FNullTag *=nullptr)
 
template<typename OtherType >
 TSharedPtr (OtherType *InObject)
 
template<typename OtherType , typename DeleterType >
 TSharedPtr (OtherType *InObject, DeleterType &&InDeleter)
 
template<typename OtherType >
 TSharedPtr (SharedPointerInternals::TRawPtrProxy< OtherType > const &InRawPtrProxy)
 
template<typename OtherType , typename DeleterType >
 TSharedPtr (SharedPointerInternals::TRawPtrProxyWithDeleter< OtherType, DeleterType > const &InRawPtrProxy)
 
template<typename OtherType , typename DeleterType >
 TSharedPtr (SharedPointerInternals::TRawPtrProxyWithDeleter< OtherType, DeleterType > &&InRawPtrProxy)
 
template<typename OtherType >
 TSharedPtr (TSharedPtr< OtherType, Mode > const &InSharedPtr)
 
 TSharedPtr (TSharedPtr const &InSharedPtr)
 
 TSharedPtr (TSharedPtr &&InSharedPtr)
 
template<typename OtherType >
 TSharedPtr (TSharedRef< OtherType, Mode > const &InSharedRef)
 
template<typename OtherType >
 TSharedPtr (TSharedPtr< OtherType, Mode > const &InSharedPtr, SharedPointerInternals::FStaticCastTag)
 
template<typename OtherType >
 TSharedPtr (TSharedPtr< OtherType, Mode > const &InSharedPtr, SharedPointerInternals::FConstCastTag)
 
template<typename OtherType >
 TSharedPtr (TSharedPtr< OtherType, Mode > const &OtherSharedPtr, ObjectType *InObject)
 
template<typename OtherType >
 TSharedPtr (TSharedPtr< OtherType, Mode > &&OtherSharedPtr, ObjectType *InObject)
 
template<typename OtherType >
 TSharedPtr (TSharedRef< OtherType, Mode > const &OtherSharedRef, ObjectType *InObject)
 
TSharedPtroperator= (SharedPointerInternals::FNullTag *)
 
TSharedPtroperator= (TSharedPtr const &InSharedPtr)
 
PGO_LINK_DISABLE_WARNINGS TSharedPtroperator= (TSharedPtr &&InSharedPtr)
 
template<typename OtherType >
PGO_LINK_ENABLE_WARNINGS TSharedPtroperator= (SharedPointerInternals::TRawPtrProxy< OtherType > const &InRawPtrProxy)
 
template<typename OtherType , typename DeleterType >
TSharedPtroperator= (SharedPointerInternals::TRawPtrProxyWithDeleter< OtherType, DeleterType > const &InRawPtrProxy)
 
template<typename OtherType , typename DeleterType >
TSharedPtroperator= (SharedPointerInternals::TRawPtrProxyWithDeleter< OtherType, DeleterType > &&InRawPtrProxy)
 
TSharedRef< ObjectType, ModeToSharedRef () const &
 
TSharedRef< ObjectType, ModeToSharedRef () &&
 
UE_FORCEINLINE_HINT TWeakPtr< ObjectType, ModeToWeakPtr () const
 
UE_FORCEINLINE_HINT ObjectType * Get () const
 
UE_FORCEINLINE_HINT operator bool () const
 
UE_FORCEINLINE_HINT const bool IsValid () const
 
template<typename DummyObjectType = ObjectType UE_REQUIRES(UE_REQUIRES_EXPR(*(DummyObjectType*)nullptr))>
DummyObjectTypeoperator* () const
 
ObjectType * operator-> () const
 
UE_FORCEINLINE_HINT void Reset ()
 
UE_FORCEINLINE_HINT int32 GetSharedReferenceCount () const
 
UE_FORCEINLINE_HINT bool IsUnique () const
 
 TSharedPtr (FIntrusiveUnsetOptionalState)
 
bool UEOpEquals (FIntrusiveUnsetOptionalState) const
 
template<typename OtherType >
bool UEOpEquals (const TSharedPtr< OtherType, Mode > &Rhs) const
 
template<typename OtherType >
UE_REWRITE bool UEOpEquals (const TWeakPtr< OtherType, Mode > &Rhs) const
 
UE_REWRITE bool UEOpEquals (TYPE_OF_NULLPTR) const
 
template<typename OtherType >
bool UEOpLessThan (const TSharedPtr< OtherType, Mode > &Rhs) const
 

Static Public Attributes

static constexpr ESPMode Mode = InMode
 
static constexpr bool bHasIntrusiveUnsetOptionalState = true
 

Friends

template<class OtherType , ESPMode OtherMode>
class TSharedPtr
 
template<class OtherType , ESPMode OtherMode>
class TSharedRef
 
template<class OtherType , ESPMode OtherMode>
class TWeakPtr
 
template<class OtherType , ESPMode OtherMode>
class TSharedFromThis
 

Detailed Description

template<class ObjectType, ESPMode InMode>
class TSharedPtr< ObjectType, InMode >

TSharedPtr is a non-intrusive reference-counted authoritative object pointer. This shared pointer will be conditionally thread-safe when the optional Mode template argument is set to ThreadSafe.

Examples
/work/Engine/Source/Runtime/UMG/Public/Components/Widget.h.

Member Typedef Documentation

◆ ElementType

template<class ObjectType , ESPMode InMode>
using TSharedPtr< ObjectType, InMode >::ElementType = ObjectType

◆ IntrusiveUnsetOptionalStateType

template<class ObjectType , ESPMode InMode>
using TSharedPtr< ObjectType, InMode >::IntrusiveUnsetOptionalStateType = TSharedPtr

Constructor & Destructor Documentation

◆ TSharedPtr() [1/16]

template<class ObjectType , ESPMode InMode>
TSharedPtr< ObjectType, InMode >::TSharedPtr ( SharedPointerInternals::FNullTag = nullptr)
inline

Constructs an empty shared pointer

◆ TSharedPtr() [2/16]

template<class ObjectType , ESPMode InMode>
template<typename OtherType >
TSharedPtr< ObjectType, InMode >::TSharedPtr ( OtherType InObject)
inlineexplicit

Constructs a shared pointer that owns the specified object. Note that passing nullptr here will still create a tracked reference to a nullptr pointer. (Consistent with std::shared_ptr)

Parameters
InObjectObject this shared pointer to retain a reference to

◆ TSharedPtr() [3/16]

template<class ObjectType , ESPMode InMode>
template<typename OtherType , typename DeleterType >
TSharedPtr< ObjectType, InMode >::TSharedPtr ( OtherType InObject,
DeleterType &&  InDeleter 
)
inline

Constructs a shared pointer that owns the specified object. Note that passing nullptr here will still create a tracked reference to a nullptr pointer. (Consistent with std::shared_ptr)

Parameters
InObjectObject this shared pointer to retain a reference to
InDeleterDeleter object used to destroy the object when it is no longer referenced.

◆ TSharedPtr() [4/16]

template<class ObjectType , ESPMode InMode>
template<typename OtherType >
TSharedPtr< ObjectType, InMode >::TSharedPtr ( SharedPointerInternals::TRawPtrProxy< OtherType > const &  InRawPtrProxy)
inline

Constructs a shared pointer using a proxy reference to a raw pointer. (See MakeShareable())

Parameters
InRawPtrProxyProxy raw pointer that contains the object that the new shared pointer will reference

◆ TSharedPtr() [5/16]

template<class ObjectType , ESPMode InMode>
template<typename OtherType , typename DeleterType >
TSharedPtr< ObjectType, InMode >::TSharedPtr ( SharedPointerInternals::TRawPtrProxyWithDeleter< OtherType, DeleterType > const &  InRawPtrProxy)
inline

Constructs a shared pointer using a proxy reference to a raw pointer. (See MakeShareable())

Parameters
InRawPtrProxyProxy raw pointer that contains the object that the new shared pointer will reference

◆ TSharedPtr() [6/16]

template<class ObjectType , ESPMode InMode>
template<typename OtherType , typename DeleterType >
TSharedPtr< ObjectType, InMode >::TSharedPtr ( SharedPointerInternals::TRawPtrProxyWithDeleter< OtherType, DeleterType > &&  InRawPtrProxy)
inline

Constructs a shared pointer using a proxy reference to a raw pointer. (See MakeShareable())

Parameters
InRawPtrProxyProxy raw pointer that contains the object that the new shared pointer will reference

◆ TSharedPtr() [7/16]

template<class ObjectType , ESPMode InMode>
template<typename OtherType >
TSharedPtr< ObjectType, InMode >::TSharedPtr ( TSharedPtr< OtherType, Mode > const &  InSharedPtr)
inline

Constructs a shared pointer as a shared reference to an existing shared pointer's object. This constructor is needed so that we can implicitly upcast to base classes.

Parameters
InSharedPtrThe shared pointer whose object we should create an additional reference to

◆ TSharedPtr() [8/16]

template<class ObjectType , ESPMode InMode>
TSharedPtr< ObjectType, InMode >::TSharedPtr ( TSharedPtr< ObjectType, InMode > const &  InSharedPtr)
inline

◆ TSharedPtr() [9/16]

template<class ObjectType , ESPMode InMode>
TSharedPtr< ObjectType, InMode >::TSharedPtr ( TSharedPtr< ObjectType, InMode > &&  InSharedPtr)
inline

◆ TSharedPtr() [10/16]

template<class ObjectType , ESPMode InMode>
template<typename OtherType >
TSharedPtr< ObjectType, InMode >::TSharedPtr ( TSharedRef< OtherType, Mode > const &  InSharedRef)
inline

Implicitly converts a shared reference to a shared pointer, adding a reference to the object. NOTE: We allow an implicit conversion from TSharedRef to TSharedPtr because it's always a safe conversion.

Parameters
InSharedRefThe shared reference that will be converted to a shared pointer

◆ TSharedPtr() [11/16]

template<class ObjectType , ESPMode InMode>
template<typename OtherType >
TSharedPtr< ObjectType, InMode >::TSharedPtr ( TSharedPtr< OtherType, Mode > const &  InSharedPtr,
SharedPointerInternals::FStaticCastTag   
)
inline

Special constructor used internally to statically cast one shared pointer type to another. You should never call this constructor directly. Instead, use the StaticCastSharedPtr() function. This constructor creates a shared pointer as a shared reference to an existing shared pointer after statically casting that pointer's object. This constructor is needed for static casts.

Parameters
InSharedPtrThe shared pointer whose object we should create an additional reference to

◆ TSharedPtr() [12/16]

template<class ObjectType , ESPMode InMode>
template<typename OtherType >
TSharedPtr< ObjectType, InMode >::TSharedPtr ( TSharedPtr< OtherType, Mode > const &  InSharedPtr,
SharedPointerInternals::FConstCastTag   
)
inline

Special constructor used internally to cast a 'const' shared pointer a 'mutable' pointer. You should never call this constructor directly. Instead, use the ConstCastSharedPtr() function. This constructor creates a shared pointer as a shared reference to an existing shared pointer after const casting that pointer's object. This constructor is needed for const casts.

Parameters
InSharedPtrThe shared pointer whose object we should create an additional reference to

◆ TSharedPtr() [13/16]

template<class ObjectType , ESPMode InMode>
template<typename OtherType >
TSharedPtr< ObjectType, InMode >::TSharedPtr ( TSharedPtr< OtherType, Mode > const &  OtherSharedPtr,
ObjectType *  InObject 
)
inline

Aliasing constructor used to create a shared pointer which shares its reference count with another shared object, but pointing to a different object, typically a subobject.

Parameters
OtherSharedPtrThe shared pointer whose reference count should be shared.
InObjectThe object pointer to use (instead of the incoming shared pointer's object)

◆ TSharedPtr() [14/16]

template<class ObjectType , ESPMode InMode>
template<typename OtherType >
TSharedPtr< ObjectType, InMode >::TSharedPtr ( TSharedPtr< OtherType, Mode > &&  OtherSharedPtr,
ObjectType *  InObject 
)
inline

Aliasing constructor used to create a shared pointer which shares its reference count with another shared object, but pointing to a different object, typically a subobject.

Parameters
OtherSharedPtrThe shared pointer whose reference count should be shared.
InObjectThe object pointer to use (instead of the incoming shared pointer's object)

◆ TSharedPtr() [15/16]

template<class ObjectType , ESPMode InMode>
template<typename OtherType >
TSharedPtr< ObjectType, InMode >::TSharedPtr ( TSharedRef< OtherType, Mode > const &  OtherSharedRef,
ObjectType *  InObject 
)
inline

Aliasing constructor used to create a shared pointer which shares its reference count with another shared object, but pointing to a different object, typically a subobject.

Parameters
OtherSharedRefThe shared reference whose reference count should be shared.
InObjectThe object pointer to use (instead of the incoming shared pointer's object)

◆ TSharedPtr() [16/16]

template<class ObjectType , ESPMode InMode>
TSharedPtr< ObjectType, InMode >::TSharedPtr ( FIntrusiveUnsetOptionalState  )
inlineexplicit

Member Function Documentation

◆ Get()

template<class ObjectType , ESPMode InMode>
UE_FORCEINLINE_HINT ObjectType * TSharedPtr< ObjectType, InMode >::Get ( ) const
inline

Returns the object referenced by this pointer, or nullptr if no object is reference

Returns
The object owned by this shared pointer, or nullptr

◆ GetSharedReferenceCount()

template<class ObjectType , ESPMode InMode>
UE_FORCEINLINE_HINT int32 TSharedPtr< ObjectType, InMode >::GetSharedReferenceCount ( ) const
inline

Returns the number of shared references to this object (including this reference.) IMPORTANT: Not necessarily fast! Should only be used for debugging purposes!

Returns
Number of shared references to the object (including this reference.)

◆ IsUnique()

template<class ObjectType , ESPMode InMode>
UE_FORCEINLINE_HINT bool TSharedPtr< ObjectType, InMode >::IsUnique ( ) const
inline

Returns true if this is the only shared reference to this object. Note that there may be outstanding weak references left. IMPORTANT: Not necessarily fast! Should only be used for debugging purposes!

Returns
True if there is only one shared reference to the object, and this is it!

◆ IsValid()

template<class ObjectType , ESPMode InMode>
UE_FORCEINLINE_HINT const bool TSharedPtr< ObjectType, InMode >::IsValid ( ) const
inline

Checks to see if this shared pointer is actually pointing to an object

Returns
True if the shared pointer is valid and can be dereferenced

◆ operator bool()

template<class ObjectType , ESPMode InMode>
UE_FORCEINLINE_HINT TSharedPtr< ObjectType, InMode >::operator bool ( ) const
inlineexplicit

Checks to see if this shared pointer is actually pointing to an object

Returns
True if the shared pointer is valid and can be dereferenced

◆ operator*()

template<class ObjectType , ESPMode InMode>
template<typename DummyObjectType = ObjectType UE_REQUIRES(UE_REQUIRES_EXPR(*(DummyObjectType*)nullptr))>
DummyObjectType & TSharedPtr< ObjectType, InMode >::operator* ( ) const
inline

Dereference operator returns a reference to the object this shared pointer points to

Returns
Reference to the object

◆ operator->()

template<class ObjectType , ESPMode InMode>
ObjectType * TSharedPtr< ObjectType, InMode >::operator-> ( ) const
inline

Arrow operator returns a pointer to the object this shared pointer references

Returns
Returns a pointer to the object referenced by this shared pointer

◆ operator=() [1/6]

template<class ObjectType , ESPMode InMode>
TSharedPtr & TSharedPtr< ObjectType, InMode >::operator= ( SharedPointerInternals::FNullTag )
inline

Assignment to a nullptr pointer. The object currently referenced by this shared pointer will no longer be referenced and will be deleted if there are no other referencers.

◆ operator=() [2/6]

template<class ObjectType , ESPMode InMode>
template<typename OtherType >
PGO_LINK_ENABLE_WARNINGS TSharedPtr & TSharedPtr< ObjectType, InMode >::operator= ( SharedPointerInternals::TRawPtrProxy< OtherType > const &  InRawPtrProxy)
inline

Assignment operator replaces this shared pointer with the specified shared pointer. The object currently referenced by this shared pointer will no longer be referenced and will be deleted if there are no other referencers.

Parameters
InRawPtrProxyProxy object used to assign the object (see MakeShareable helper function)

◆ operator=() [3/6]

template<class ObjectType , ESPMode InMode>
template<typename OtherType , typename DeleterType >
TSharedPtr & TSharedPtr< ObjectType, InMode >::operator= ( SharedPointerInternals::TRawPtrProxyWithDeleter< OtherType, DeleterType > &&  InRawPtrProxy)
inline

Assignment operator replaces this shared pointer with the specified shared pointer. The object currently referenced by this shared pointer will no longer be referenced and will be deleted if there are no other referencers.

Parameters
InRawPtrProxyProxy object used to assign the object (see MakeShareable helper function)

◆ operator=() [4/6]

template<class ObjectType , ESPMode InMode>
template<typename OtherType , typename DeleterType >
TSharedPtr & TSharedPtr< ObjectType, InMode >::operator= ( SharedPointerInternals::TRawPtrProxyWithDeleter< OtherType, DeleterType > const &  InRawPtrProxy)
inline

Assignment operator replaces this shared pointer with the specified shared pointer. The object currently referenced by this shared pointer will no longer be referenced and will be deleted if there are no other referencers.

Parameters
InRawPtrProxyProxy object used to assign the object (see MakeShareable helper function)

◆ operator=() [5/6]

template<class ObjectType , ESPMode InMode>
PGO_LINK_DISABLE_WARNINGS TSharedPtr & TSharedPtr< ObjectType, InMode >::operator= ( TSharedPtr< ObjectType, InMode > &&  InSharedPtr)
inline

◆ operator=() [6/6]

template<class ObjectType , ESPMode InMode>
TSharedPtr & TSharedPtr< ObjectType, InMode >::operator= ( TSharedPtr< ObjectType, InMode > const &  InSharedPtr)
inline

Assignment operator replaces this shared pointer with the specified shared pointer. The object currently referenced by this shared pointer will no longer be referenced and will be deleted if there are no other referencers.

Parameters
InSharedPtrShared pointer to replace with

◆ Reset()

template<class ObjectType , ESPMode InMode>
UE_FORCEINLINE_HINT void TSharedPtr< ObjectType, InMode >::Reset ( )
inline

Resets this shared pointer, removing a reference to the object. If there are no other shared references to the object then it will be destroyed.

◆ ToSharedRef() [1/2]

template<class ObjectType , ESPMode InMode>
TSharedRef< ObjectType, Mode > TSharedPtr< ObjectType, InMode >::ToSharedRef ( ) &&
inline

Converts a shared pointer to a shared reference. The pointer must be valid or an assertion will trigger.

Returns
Reference to the object

◆ ToSharedRef() [2/2]

template<class ObjectType , ESPMode InMode>
TSharedRef< ObjectType, Mode > TSharedPtr< ObjectType, InMode >::ToSharedRef ( ) const &
inline

Converts a shared pointer to a shared reference. The pointer must be valid or an assertion will trigger.

Returns
Reference to the object

◆ ToWeakPtr()

template<class ObjectType , ESPMode InMode>
UE_FORCEINLINE_HINT TWeakPtr< ObjectType, Mode > TSharedPtr< ObjectType, InMode >::ToWeakPtr ( ) const
inline

Converts a shared pointer to a weak ptr.

Returns
Weak pointer to the object

◆ UEOpEquals() [1/4]

template<class ObjectType , ESPMode InMode>
template<typename OtherType >
bool TSharedPtr< ObjectType, InMode >::UEOpEquals ( const TSharedPtr< OtherType, Mode > &  Rhs) const
inline

◆ UEOpEquals() [2/4]

template<class ObjectType , ESPMode InMode>
template<typename OtherType >
UE_REWRITE bool TSharedPtr< ObjectType, InMode >::UEOpEquals ( const TWeakPtr< OtherType, Mode > &  Rhs) const
inline

◆ UEOpEquals() [3/4]

template<class ObjectType , ESPMode InMode>
bool TSharedPtr< ObjectType, InMode >::UEOpEquals ( FIntrusiveUnsetOptionalState  ) const
inline

◆ UEOpEquals() [4/4]

template<class ObjectType , ESPMode InMode>
UE_REWRITE bool TSharedPtr< ObjectType, InMode >::UEOpEquals ( TYPE_OF_NULLPTR  ) const
inline

◆ UEOpLessThan()

template<class ObjectType , ESPMode InMode>
template<typename OtherType >
bool TSharedPtr< ObjectType, InMode >::UEOpLessThan ( const TSharedPtr< OtherType, Mode > &  Rhs) const
inline

Friends And Related Symbol Documentation

◆ TSharedFromThis

template<class ObjectType , ESPMode InMode>
template<class OtherType , ESPMode OtherMode>
friend class TSharedFromThis
friend

◆ TSharedPtr

template<class ObjectType , ESPMode InMode>
template<class OtherType , ESPMode OtherMode>
friend class TSharedPtr
friend

◆ TSharedRef

template<class ObjectType , ESPMode InMode>
template<class OtherType , ESPMode OtherMode>
friend class TSharedRef
friend

◆ TWeakPtr

template<class ObjectType , ESPMode InMode>
template<class OtherType , ESPMode OtherMode>
friend class TWeakPtr
friend

Member Data Documentation

◆ bHasIntrusiveUnsetOptionalState

template<class ObjectType , ESPMode InMode>
constexpr bool TSharedPtr< ObjectType, InMode >::bHasIntrusiveUnsetOptionalState = true
staticconstexpr

◆ Mode

template<class ObjectType , ESPMode InMode>
constexpr ESPMode TSharedPtr< ObjectType, InMode >::Mode = InMode
staticconstexpr

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