more constexprs

# Conflicts:
#	Engine/source/core/util/refBase.h
This commit is contained in:
Triston Caton 2025-10-05 13:00:40 -04:00
parent 8d1e95b3f3
commit c24d0211bd

View file

@ -55,6 +55,7 @@ public:
friend class WeakRefBase; friend class WeakRefBase;
constexpr explicit WeakReference(WeakRefBase *object) :mObject(object), mRefCount(0) {} constexpr explicit WeakReference(WeakRefBase *object) :mObject(object), mRefCount(0) {}
~WeakReference() { AssertFatal(mObject==nullptr, "Deleting weak reference which still points at an object."); } ~WeakReference() { AssertFatal(mObject==nullptr, "Deleting weak reference which still points at an object."); }
// Object we reference // Object we reference
@ -111,9 +112,9 @@ public:
/// Returns true if the pointer is set. /// Returns true if the pointer is set.
[[nodiscard]] constexpr bool isValid() const { return mReference && mReference->get(); } [[nodiscard]] constexpr bool isValid() const { return mReference && mReference->get(); }
T* operator->() const { return getPointer(); } [[nodiscard]] constexpr T* operator->() const { return getPointer(); }
T& operator*() const { return *getPointer(); } [[nodiscard]] constexpr T& operator*() const { return *getPointer(); }
operator T*() const { return getPointer(); } [[nodiscard]] constexpr operator T*() const { return getPointer(); }
/// Returns the pointer. /// Returns the pointer.
[[nodiscard]] constexpr T* getPointer() const { return mReference ? (T*)mReference->get() : nullptr; } [[nodiscard]] constexpr T* getPointer() const { return mReference ? (T*)mReference->get() : nullptr; }
@ -146,10 +147,10 @@ class WeakRefUnion
typedef WeakRefUnion<ExposedType> Union; typedef WeakRefUnion<ExposedType> Union;
public: public:
WeakRefUnion() : mPtr(nullptr) {} constexpr WeakRefUnion() : mPtr(nullptr) {}
WeakRefUnion(const WeakRefPtr<WeakRefBase> & ref, ExposedType * ptr) : mPtr(nullptr) { set(ref, ptr); } constexpr WeakRefUnion(const WeakRefPtr<WeakRefBase> & ref, ExposedType * ptr) : mPtr(nullptr) { set(ref, ptr); }
WeakRefUnion(const Union & lock) : mPtr(nullptr) { *this = lock; } constexpr WeakRefUnion(const Union & lock) : mPtr(nullptr) { *this = lock; }
WeakRefUnion(WeakRefBase * ref) : mPtr(nullptr) { set(ref, dynamic_cast<ExposedType*>(ref)); } constexpr WeakRefUnion(WeakRefBase * ref) : mPtr(nullptr) { set(ref, dynamic_cast<ExposedType*>(ref)); }
~WeakRefUnion() { mWeakReference = nullptr; } ~WeakRefUnion() { mWeakReference = nullptr; }
Union & operator=(const Union & ptr) Union & operator=(const Union & ptr)
@ -454,17 +455,17 @@ struct TypeTraits< StrongWeakRefPtr< T > > : public _TypeTraits< StrongWeakRefPt
}; };
template< typename T > template< typename T >
inline T& Deref( WeakRefPtr< T >& ref ) [[nodiscard]] constexpr T& Deref( WeakRefPtr< T >& ref )
{ {
return *ref; return *ref;
} }
template< typename T > template< typename T >
inline T& Deref( StrongRefPtr< T >& ref ) [[nodiscard]] constexpr T& Deref( StrongRefPtr< T >& ref )
{ {
return *ref; return *ref;
} }
template< typename T > template< typename T >
inline T& Deref( StrongWeakRefPtr< T >& ref ) [[nodiscard]] constexpr T& Deref( StrongWeakRefPtr< T >& ref )
{ {
return *ref; return *ref;
} }