network: (fixes #2551) Use std::array and three-way comparison operator in Ipv(4/6) classes

I picked this up on the @tommypec 's suggestion in !2609 (merged) - created a new MR since I didn't have push access to the branch used in the previous MR (!2551 (closed) ).

  • Replaced the C-style arrays with C++ std:array in the Ipv6 address class
  • Removed unnecessary operators (<, >, !=) from the Ipv(4/6) address classes
  • Added the three-way comparison operator to both
  • Added the equality operator to both

Since the default three-way comparison operator compares the classes lexicographically, the following member

bool m_initialized;

will also be taken into consideration during comparison, which is not desirable. This is why I've used a custom three-way comparison that defines it as the three-way comparison of the address member only.

inline std::strong_ordering
Ipv6Address::operator<=>(const Ipv6Address& other) const
{
    return m_address <=> other.m_address;
}

And since I'm not using the default definition of the operator, I also had to define the equality operator separately. Please let me know if I've missed out on anything, thanks again!

Merge request reports

Loading
Loading