RealDocs

TWeakPtr::UEOpEquals

function Core Since 5.0
#include "Templates/SharedPointer.h"
Access: public Specifiers: constinline

Description

Equality comparison for TWeakPtr that pins both sides to shared pointers and compares the resulting raw pointers. Used by operator== and also by the intrusive TOptional mechanism to detect unset state.

Caveats & Gotchas

  • Because it pins both sides, UEOpEquals temporarily extends the lifetimes of both objects during the comparison — this is thread-safe in ThreadSafe mode but has a non-trivial overhead compared to a raw pointer comparison.
  • A second overload `UEOpEquals(FIntrusiveUnsetOptionalState)` exists that checks whether `Object == (ObjectType*)-1`, which is the sentinel value used by TOptional<TWeakPtr>; this sentinel comparison bypasses the Pin() logic entirely.

Signature

template <typename OtherType> [[nodiscard]] inline bool UEOpEquals(const TWeakPtr<OtherType, Mode>& Rhs) const

Parameters

Name Type Description Default
Rhs const TWeakPtr<OtherType, Mode>& The other weak pointer to compare against.

Return Type

bool

Example

Comparing two weak pointers C++
TSharedPtr<FMyService> ServiceA = MakeShared<FMyService>();
TWeakPtr<FMyService> WeakA = ServiceA;
TWeakPtr<FMyService> WeakB = ServiceA;

// Both point to the same object — operator== delegates to UEOpEquals
check(WeakA == WeakB);

// After expiry both become invalid but are still equal (both Pin() to nullptr)
ServiceA.Reset();
check(WeakA == WeakB); // still true: nullptr == nullptr

Version History

Introduced in: 5.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.