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

#include <SharedPointer.h>

Public Types

using ElementType = ObjectType
 
using IntrusiveUnsetOptionalStateType = TSharedRef
 

Public Member Functions

template<typename OtherType >
 TSharedRef (OtherType *InObject)
 
template<typename OtherType , typename DeleterType >
 TSharedRef (OtherType *InObject, DeleterType &&InDeleter)
 
 TSharedRef ()
 
template<typename OtherType >
 TSharedRef (SharedPointerInternals::TRawPtrProxy< OtherType > const &InRawPtrProxy)
 
template<typename OtherType , typename DeleterType >
 TSharedRef (SharedPointerInternals::TRawPtrProxyWithDeleter< OtherType, DeleterType > const &InRawPtrProxy)
 
template<typename OtherType , typename DeleterType >
 TSharedRef (SharedPointerInternals::TRawPtrProxyWithDeleter< OtherType, DeleterType > &&InRawPtrProxy)
 
template<typename OtherType >
 TSharedRef (TSharedRef< OtherType, Mode > const &InSharedRef)
 
template<typename OtherType >
 TSharedRef (TSharedRef< OtherType, Mode > const &InSharedRef, SharedPointerInternals::FStaticCastTag)
 
template<typename OtherType >
 TSharedRef (TSharedRef< OtherType, Mode > const &InSharedRef, SharedPointerInternals::FConstCastTag)
 
template<typename OtherType >
 TSharedRef (TSharedRef< OtherType, Mode > const &OtherSharedRef, ObjectType *InObject)
 
 TSharedRef (TSharedRef const &InSharedRef)
 
 TSharedRef (TSharedRef &&InSharedRef)
 
TSharedRefoperator= (TSharedRef const &InSharedRef)
 
TSharedRefoperator= (TSharedRef &&InSharedRef)
 
template<typename OtherType >
TSharedRefoperator= (SharedPointerInternals::TRawPtrProxy< OtherType > const &InRawPtrProxy)
 
template<typename OtherType , typename DeleterType >
TSharedRefoperator= (SharedPointerInternals::TRawPtrProxyWithDeleter< OtherType, DeleterType > const &InRawPtrProxy)
 
template<typename OtherType , typename DeleterType >
TSharedRefoperator= (SharedPointerInternals::TRawPtrProxyWithDeleter< OtherType, DeleterType > &&InRawPtrProxy)
 
UE_FORCEINLINE_HINT TSharedPtr< ObjectType, ModeToSharedPtr () const
 
UE_FORCEINLINE_HINT TWeakPtr< ObjectType, ModeToWeakPtr () const
 
ObjectType & Get () const
 
ObjectType & operator* () const
 
ObjectType * operator-> () const
 
UE_FORCEINLINE_HINT int32 GetSharedReferenceCount () const
 
UE_FORCEINLINE_HINT bool IsUnique () const
 
 TSharedRef (FIntrusiveUnsetOptionalState)
 
bool UEOpEquals (FIntrusiveUnsetOptionalState) const
 
template<typename OtherType >
bool UEOpEquals (const TSharedRef< OtherType, Mode > &Rhs) const
 
template<typename OtherType >
bool UEOpEquals (const TSharedPtr< OtherType, Mode > &Rhs) const
 
template<typename OtherType >
bool UEOpEquals (const TWeakPtr< OtherType, Mode > &Rhs) const
 
template<typename OtherType >
bool UEOpLessThan (const TSharedRef< OtherType, Mode > &Rhs) const
 

Static Public Attributes

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

Friends

template<class OtherType , ESPMode OtherMode>
class TSharedRef
 
template<class OtherType , ESPMode OtherMode>
class TSharedPtr
 
template<class OtherType , ESPMode OtherMode>
class TWeakPtr
 
TSharedRef UE::Core::Private::MakeSharedRef (ObjectType *InObject, SharedPointerInternals::TReferenceControllerBase< Mode > *InSharedReferenceCount)
 

Detailed Description

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

TSharedRef is a non-nullable, non-intrusive reference-counted authoritative object reference.

This shared reference 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 TSharedRef< ObjectType, InMode >::ElementType = ObjectType

◆ IntrusiveUnsetOptionalStateType

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

Constructor & Destructor Documentation

◆ TSharedRef() [1/13]

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

Constructs a shared reference that owns the specified object. Must not be nullptr.

Parameters
InObjectObject this shared reference to retain a reference to

◆ TSharedRef() [2/13]

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

Constructs a shared reference that owns the specified object. Must not be nullptr.

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

◆ TSharedRef() [3/13]

template<class ObjectType , ESPMode InMode>
TSharedRef< ObjectType, InMode >::TSharedRef ( )
inline

Constructs default shared reference that owns the default object for specified type.

Used internally only. Please do not use!

◆ TSharedRef() [4/13]

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

Constructs a shared reference using a proxy reference to a raw pointer. (See MakeShareable()) Must not be nullptr.

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

◆ TSharedRef() [5/13]

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

Constructs a shared reference using a proxy reference to a raw pointer. (See MakeShareable()) Must not be nullptr.

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

◆ TSharedRef() [6/13]

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

Constructs a shared reference using a proxy reference to a raw pointer. (See MakeShareable()) Must not be nullptr.

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

◆ TSharedRef() [7/13]

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

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

Parameters
InSharedRefThe shared reference whose object we should create an additional reference to

◆ TSharedRef() [8/13]

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

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

Parameters
InSharedRefThe shared reference whose object we should create an additional reference to

◆ TSharedRef() [9/13]

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

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

Parameters
InSharedRefThe shared reference whose object we should create an additional reference to

◆ TSharedRef() [10/13]

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

Aliasing constructor used to create a shared reference 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)

◆ TSharedRef() [11/13]

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

◆ TSharedRef() [12/13]

template<class ObjectType , ESPMode InMode>
TSharedRef< ObjectType, InMode >::TSharedRef ( TSharedRef< ObjectType, InMode > &&  InSharedRef)
inline

◆ TSharedRef() [13/13]

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

Member Function Documentation

◆ Get()

template<class ObjectType , ESPMode InMode>
ObjectType & TSharedRef< ObjectType, InMode >::Get ( ) const
inline

Returns a C++ reference to the object this shared reference is referencing

Returns
The object owned by this shared reference

◆ GetSharedReferenceCount()

template<class ObjectType , ESPMode InMode>
UE_FORCEINLINE_HINT int32 TSharedRef< 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 TSharedRef< 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: This has different behavior to GetSharedReferenceCount() == 1 in a multithreaded context. The expectation is that this will be used when a user wants exclusive write-access to an otherwise-immutable object. Care still needs to be taken when pinning TWeakPtrs to make new shared references.

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

◆ operator*()

template<class ObjectType , ESPMode InMode>
ObjectType & TSharedRef< 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 * TSharedRef< ObjectType, InMode >::operator-> ( ) const
inline

Arrow operator returns a pointer to this shared reference's object

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

◆ operator=() [1/5]

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

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

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

◆ operator=() [2/5]

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

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

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

◆ operator=() [3/5]

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

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

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

◆ operator=() [4/5]

template<class ObjectType , ESPMode InMode>
TSharedRef & TSharedRef< ObjectType, InMode >::operator= ( TSharedRef< ObjectType, InMode > &&  InSharedRef)
inline

◆ operator=() [5/5]

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

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

Parameters
InSharedRefShared reference to replace with

◆ ToSharedPtr()

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

Converts a shared reference to a shared pointer.

Returns
Shared pointer to the object

◆ ToWeakPtr()

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

Converts a shared reference to a weak ptr.

Returns
Weak pointer to the object

◆ UEOpEquals() [1/4]

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

◆ UEOpEquals() [2/4]

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

◆ UEOpEquals() [3/4]

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

◆ UEOpEquals() [4/4]

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

◆ UEOpLessThan()

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

Friends And Related Symbol Documentation

◆ 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

◆ UE::Core::Private::MakeSharedRef

template<class ObjectType , ESPMode InMode>
TSharedRef UE::Core::Private::MakeSharedRef ( ObjectType *  InObject,
SharedPointerInternals::TReferenceControllerBase< Mode > *  InSharedReferenceCount 
)
friend

Member Data Documentation

◆ bHasIntrusiveUnsetOptionalState

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

◆ Mode

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

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