HeapArray: Fix comparison operators

This commit is contained in:
chaoticgd
2026-03-16 22:37:04 +00:00
committed by Ty
parent 5d811f03f4
commit d856f3f5bd
+16 -34
View File
@@ -87,24 +87,15 @@ public:
return *this;
}
#define RELATIONAL_OPERATOR(op) \
bool operator op(const this_type& rhs) const \
{ \
for (size_type i = 0; i < SIZE; i++) \
{ \
if (!(m_data[i] op rhs.m_data[i])) \
return false; \
} \
bool operator==(const this_type& rhs) const
{
return std::equal(m_data, m_data + SIZE, rhs.m_data, rhs.m_data + SIZE);
}
RELATIONAL_OPERATOR(==);
RELATIONAL_OPERATOR(!=);
RELATIONAL_OPERATOR(<);
RELATIONAL_OPERATOR(<=);
RELATIONAL_OPERATOR(>);
RELATIONAL_OPERATOR(>=);
#undef RELATIONAL_OPERATOR
auto operator<=>(const this_type& rhs) const
{
return std::lexicographical_compare_three_way(m_data, m_data + SIZE, rhs.m_data, rhs.m_data + SIZE);
}
private:
void allocate()
@@ -337,26 +328,17 @@ public:
return *this;
}
#define RELATIONAL_OPERATOR(op, size_op) \
bool operator op(const this_type& rhs) const \
{ \
if (m_size != rhs.m_size) \
return m_size size_op rhs.m_size; \
for (size_type i = 0; i < m_size; i++) \
{ \
if (!(m_data[i] op rhs.m_data[i])) \
return false; \
} \
bool operator==(const this_type& rhs) const
{
return std::equal(m_data, m_data + m_size, rhs.m_data, rhs.m_data + rhs.m_size);
}
RELATIONAL_OPERATOR(==, !=);
RELATIONAL_OPERATOR(!=, ==);
RELATIONAL_OPERATOR(<, <);
RELATIONAL_OPERATOR(<=, <=);
RELATIONAL_OPERATOR(>, >);
RELATIONAL_OPERATOR(>=, >=);
#undef RELATIONAL_OPERATOR
auto operator<=>(const this_type& rhs) const
{
return std::lexicographical_compare_three_way(
m_data, m_data + m_size,
rhs.m_data, rhs.m_data + rhs.m_size);
}
private:
void internal_resize(size_t size, T* prev_ptr, size_t prev_size)