Description
Internal equality helper used by UE's operator== rewrite infrastructure. Compares two TSharedRef instances by their managed Object pointer. Overloads also accept TSharedPtr, TWeakPtr, and FIntrusiveUnsetOptionalState.
Caveats & Gotchas
- • UEOpEquals is not operator== — it is called by the UE_REWRITE-generated equality operator. Invoke == directly in user code; do not call UEOpEquals explicitly.
- • The TSharedPtr overload has a subtle asymmetry: it returns false if the TSharedPtr is null, even though a null TSharedPtr can never equal any TSharedRef (which is always non-null). This is noted in the source as 'maintained as existing behavior'.
- • The FIntrusiveUnsetOptionalState overload enables TOptional<TSharedRef> by using a null Object as the unset sentinel. A normally constructed TSharedRef can never have a null Object, so the states are disjoint.
Signature
template <typename OtherType>
[[nodiscard]] bool UEOpEquals(const TSharedRef<OtherType, Mode>& Rhs) const Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Rhs | const TSharedRef<OtherType, Mode>& | The other shared reference to compare against. | — |
Return Type
bool Example
Comparing shared references with == C++
TSharedRef<FMyData> A = MakeShared<FMyData>();
TSharedRef<FMyData> B = A; // same object
TSharedRef<FMyData> C = MakeShared<FMyData>(); // different object
check(A == B); // true
check(A != C); // true
// Comparing ref with ptr:
TSharedPtr<FMyData> Ptr = A;
check(A == Ptr); // true — same underlying object See Also
Tags
Version History
Introduced in: 5.3
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?