Slightly improve function signatures

The member functions of the union now take all arguments const, meaning
that it is not possible to modify this value somehow. This reduces the
chance of subtle bugs and widens the contexts in which these member
functions can be used.

Furthermore, one signature took a `Key' by value while all functions
take `Key' by reference. For the sake of consistency, this was adapted
to.
pull/324/head
Max Görner 7 years ago
parent 066d00d117
commit b2254e1c7f

@ -26,29 +26,29 @@ union Key {
}; };
uint16_t raw; uint16_t raw;
constexpr inline bool operator==(uint16_t rhs) const { constexpr inline bool operator==(const uint16_t rhs) const {
return this->raw == rhs; return this->raw == rhs;
} }
constexpr inline bool operator==(const Key rhs) const { constexpr inline bool operator==(const Key& rhs) const {
return this->raw == rhs.raw; return this->raw == rhs.raw;
} }
inline Key& operator=(uint16_t raw) { inline Key& operator=(const uint16_t raw) {
this->raw = raw; this->raw = raw;
return *this; return *this;
} }
constexpr inline bool operator!=(const Key& rhs) const { constexpr inline bool operator!=(const Key& rhs) const {
return !(*this == rhs); return !(*this == rhs);
} }
constexpr inline bool operator>=(uint16_t raw) const { constexpr inline bool operator>=(const uint16_t raw) const {
return this->raw >= raw; return this->raw >= raw;
} }
constexpr inline bool operator<=(uint16_t raw) const { constexpr inline bool operator<=(const uint16_t raw) const {
return this->raw <= raw; return this->raw <= raw;
} }
constexpr inline bool operator>(uint16_t raw) const { constexpr inline bool operator>(const uint16_t raw) const {
return this->raw > raw; return this->raw > raw;
} }
constexpr inline bool operator<(uint16_t raw) const { constexpr inline bool operator<(const uint16_t raw) const {
return this->raw < raw; return this->raw < raw;
} }
constexpr inline bool operator>=(const Key& other) const { constexpr inline bool operator>=(const Key& other) const {

Loading…
Cancel
Save