joboccara / NamedType

Implementation of strong types in C++
MIT License
772 stars 85 forks source link

Missing skills mixin for equality only #63

Open CelticMinstrel opened 3 years ago

CelticMinstrel commented 3 years ago

You provide Comparable that offers both equality and relational operators, but no skills class that only provides equality.

stellarpower commented 2 years ago

This would be nice for me, I am wrapping the textbook example class - a matrix. For this, less-than or greater-than doesn't make any sense unless we do so in an explicit manner. However, equating two matrices is a very common operation.

Also, might be mnice to add the new spaceship operator too.

stellarpower commented 2 years ago

I'm also not sure about this: https://github.com/joboccara/NamedType/blob/c119054eac4b8f3599233ff480ad1ce4309a52ad/include/NamedType/underlying_functionalities.hpp#L291-L294 I don't think there's anything saying that it would be undefined behaviour if a != b was not equivalent to !(a == b), is there? It could be that a class implements inequality slightly differently from equality. I'd be tempted to use a concept (or equivalent) to check if != is already defined, and only fall back to negating == if that isn't the case, as it's a sensible thing to do.

Edit: I see now it's comparing mathematically, i.e. neither a < b nor b < a, although I still think it might be advantageous to provide for a number of ways to go about htis, as different skills will be required for different use-cases.