Add const and constexpr specifiers to Key union

Making the member functions of Key `const' explicitly flags that they
will not change the union. This will allow to use Key in const contexts.

Adding the `constexpr' specifier to the function makes it possible to
rely on the results at compile time. This puts some kind of restrictions
on the function, especially when using C++11 and not a newer standard,
but these restrictions were already fulfilled, so this seems to be safe.
pull/324/head
Max Görner 7 years ago
parent 8546814b98
commit 066d00d117

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

Loading…
Cancel
Save