diff --git a/rpcs3/Emu/Memory/vm_ptr.h b/rpcs3/Emu/Memory/vm_ptr.h index a12a2b756d..8fadef5841 100644 --- a/rpcs3/Emu/Memory/vm_ptr.h +++ b/rpcs3/Emu/Memory/vm_ptr.h @@ -13,9 +13,9 @@ namespace vm template class _ref_base; - // SFINAE helper type for vm::_ptr_base comparison operators (enables comparison between equal types and between any type and void*) - template - using if_comparable_t = std::enable_if_t::value || std::is_void::value || std::is_same, std::remove_cv_t>::value, RT>; + // Enables comparison between comparable types of pointers + template + concept PtrComparable = requires (T1* t1, T2* t2) { t1 == t2; }; template class _ptr_base @@ -56,7 +56,7 @@ namespace vm } // Enable only the conversions which are originally possible between pointer types - template::value>> + template requires (std::is_convertible_v) operator _ptr_base() const { return vm::cast(m_addr); @@ -68,28 +68,28 @@ namespace vm } // Get vm pointer to a struct member - template > + template requires PtrComparable _ptr_base ptr(MT T2::*const mptr) const { return vm::cast(vm::cast(m_addr) + offset32(mptr)); } // Get vm pointer to a struct member with array subscription - template , typename = if_comparable_t> + template > requires PtrComparable _ptr_base ptr(MT T2::*const mptr, u32 index) const { return vm::cast(vm::cast(m_addr) + offset32(mptr) + u32{sizeof(ET)} * index); } // Get vm reference to a struct member - template > + template requires PtrComparable _ref_base ref(MT T2::*const mptr) const { return vm::cast(vm::cast(m_addr) + offset32(mptr)); } // Get vm reference to a struct member with array subscription - template , typename = if_comparable_t> + template > requires PtrComparable _ref_base ref(MT T2::*const mptr, u32 index) const { return vm::cast(vm::cast(m_addr) + offset32(mptr) + u32{sizeof(ET)} * index); @@ -160,8 +160,8 @@ namespace vm } // Pointer difference operator - template - std::enable_if_t::value && std::is_same, std::decay_t>::value, s32> operator -(const _ptr_base& right) const + template requires (std::is_object_v && std::is_same_v, std::decay_t>) + s32 operator -(const _ptr_base& right) const { return static_cast(vm::cast(m_addr) - vm::cast(right.m_addr)) / size(); } @@ -204,12 +204,14 @@ namespace vm return *this; } - bool try_read(std::conditional_t, char&, std::add_lvalue_reference_t>> out) const + template requires (!std::is_void_v && !std::is_const_v) + bool try_read(std::conditional_t, char, T>& out) const { return vm::try_access(vm::cast(m_addr), &out, sizeof(T), false); } - bool try_write(std::conditional_t, const char&, std::add_lvalue_reference_t> _in) const + template requires (!std::is_void_v) + bool try_write(const std::conditional_t, char, T>& _in) const { return vm::try_access(vm::cast(m_addr), const_cast(&_in), sizeof(T), true); } @@ -373,32 +375,32 @@ namespace vm constexpr null_t null{}; } -template -inline vm::if_comparable_t operator ==(const vm::_ptr_base& left, const vm::_ptr_base& right) +template requires vm::PtrComparable +inline bool operator ==(const vm::_ptr_base& left, const vm::_ptr_base& right) { return left.addr() == right.addr(); } -template -inline vm::if_comparable_t operator <(const vm::_ptr_base& left, const vm::_ptr_base& right) +template requires vm::PtrComparable +inline bool operator <(const vm::_ptr_base& left, const vm::_ptr_base& right) { return left.addr() < right.addr(); } -template -inline vm::if_comparable_t operator <=(const vm::_ptr_base& left, const vm::_ptr_base& right) +template requires vm::PtrComparable +inline bool operator <=(const vm::_ptr_base& left, const vm::_ptr_base& right) { return left.addr() <= right.addr(); } -template -inline vm::if_comparable_t operator >(const vm::_ptr_base& left, const vm::_ptr_base& right) +template requires vm::PtrComparable +inline bool operator >(const vm::_ptr_base& left, const vm::_ptr_base& right) { return left.addr() > right.addr(); } -template -inline vm::if_comparable_t operator >=(const vm::_ptr_base& left, const vm::_ptr_base& right) +template requires vm::PtrComparable +inline bool operator >=(const vm::_ptr_base& left, const vm::_ptr_base& right) { return left.addr() >= right.addr(); }