diff --git a/AK/DistinctNumeric.h b/AK/DistinctNumeric.h index 44af5a11543dfe..f6c2c67dbe02b0 100644 --- a/AK/DistinctNumeric.h +++ b/AK/DistinctNumeric.h @@ -52,48 +52,48 @@ class DistinctNumeric { using Self = DistinctNumeric; public: - DistinctNumeric() + constexpr DistinctNumeric() { } - DistinctNumeric(T value) + constexpr DistinctNumeric(T value) : m_value { value } { } - const T& value() const { return m_value; } + constexpr const T& value() const { return m_value; } // Always implemented: identity. - bool operator==(const Self& other) const + constexpr bool operator==(const Self& other) const { return this->m_value == other.m_value; } - bool operator!=(const Self& other) const + constexpr bool operator!=(const Self& other) const { return this->m_value != other.m_value; } // Only implemented when `Incr` is true: - Self& operator++() + constexpr Self& operator++() { static_assert(Incr, "'++a' is only available for DistinctNumeric types with 'Incr'."); this->m_value += 1; return *this; } - Self operator++(int) + constexpr Self operator++(int) { static_assert(Incr, "'a++' is only available for DistinctNumeric types with 'Incr'."); Self ret = this->m_value; this->m_value += 1; return ret; } - Self& operator--() + constexpr Self& operator--() { static_assert(Incr, "'--a' is only available for DistinctNumeric types with 'Incr'."); this->m_value -= 1; return *this; } - Self operator--(int) + constexpr Self operator--(int) { static_assert(Incr, "'a--' is only available for DistinctNumeric types with 'Incr'."); Self ret = this->m_value; @@ -102,22 +102,22 @@ class DistinctNumeric { } // Only implemented when `Cmp` is true: - bool operator>(const Self& other) const + constexpr bool operator>(const Self& other) const { static_assert(Cmp, "'a>b' is only available for DistinctNumeric types with 'Cmp'."); return this->m_value > other.m_value; } - bool operator<(const Self& other) const + constexpr bool operator<(const Self& other) const { static_assert(Cmp, "'am_value < other.m_value; } - bool operator>=(const Self& other) const + constexpr bool operator>=(const Self& other) const { static_assert(Cmp, "'a>=b' is only available for DistinctNumeric types with 'Cmp'."); return this->m_value >= other.m_value; } - bool operator<=(const Self& other) const + constexpr bool operator<=(const Self& other) const { static_assert(Cmp, "'a<=b' is only available for DistinctNumeric types with 'Cmp'."); return this->m_value <= other.m_value; @@ -125,7 +125,7 @@ class DistinctNumeric { // 'operator<=>' cannot be implemented. See class comment. // Only implemented when `bool` is true: - bool operator!() const + constexpr bool operator!() const { static_assert(Bool, "'!a' is only available for DistinctNumeric types with 'Bool'."); return !this->m_value; @@ -136,39 +136,39 @@ class DistinctNumeric { // `operator bool() const` would defy the entire point of this class. // Only implemented when `Flags` is true: - Self operator~() const + constexpr Self operator~() const { static_assert(Flags, "'~a' is only available for DistinctNumeric types with 'Flags'."); return ~this->m_value; } - Self operator&(const Self& other) const + constexpr Self operator&(const Self& other) const { static_assert(Flags, "'a&b' is only available for DistinctNumeric types with 'Flags'."); return this->m_value & other.m_value; } - Self operator|(const Self& other) const + constexpr Self operator|(const Self& other) const { static_assert(Flags, "'a|b' is only available for DistinctNumeric types with 'Flags'."); return this->m_value | other.m_value; } - Self operator^(const Self& other) const + constexpr Self operator^(const Self& other) const { static_assert(Flags, "'a^b' is only available for DistinctNumeric types with 'Flags'."); return this->m_value ^ other.m_value; } - Self& operator&=(const Self& other) + constexpr Self& operator&=(const Self& other) { static_assert(Flags, "'a&=b' is only available for DistinctNumeric types with 'Flags'."); this->m_value &= other.m_value; return *this; } - Self& operator|=(const Self& other) + constexpr Self& operator|=(const Self& other) { static_assert(Flags, "'a|=b' is only available for DistinctNumeric types with 'Flags'."); this->m_value |= other.m_value; return *this; } - Self& operator^=(const Self& other) + constexpr Self& operator^=(const Self& other) { static_assert(Flags, "'a^=b' is only available for DistinctNumeric types with 'Flags'."); this->m_value ^= other.m_value; @@ -177,23 +177,23 @@ class DistinctNumeric { // Only implemented when `Shift` is true: // TODO: Should this take `int` instead? - Self operator<<(const Self& other) const + constexpr Self operator<<(const Self& other) const { static_assert(Shift, "'a<m_value << other.m_value; } - Self operator>>(const Self& other) const + constexpr Self operator>>(const Self& other) const { static_assert(Shift, "'a>>b' is only available for DistinctNumeric types with 'Shift'."); return this->m_value >> other.m_value; } - Self& operator<<=(const Self& other) + constexpr Self& operator<<=(const Self& other) { static_assert(Shift, "'a<<=b' is only available for DistinctNumeric types with 'Shift'."); this->m_value <<= other.m_value; return *this; } - Self& operator>>=(const Self& other) + constexpr Self& operator>>=(const Self& other) { static_assert(Shift, "'a>>=b' is only available for DistinctNumeric types with 'Shift'."); this->m_value >>= other.m_value; @@ -201,66 +201,66 @@ class DistinctNumeric { } // Only implemented when `Arith` is true: - Self operator+(const Self& other) const + constexpr Self operator+(const Self& other) const { static_assert(Arith, "'a+b' is only available for DistinctNumeric types with 'Arith'."); return this->m_value + other.m_value; } - Self operator-(const Self& other) const + constexpr Self operator-(const Self& other) const { static_assert(Arith, "'a-b' is only available for DistinctNumeric types with 'Arith'."); return this->m_value - other.m_value; } - Self operator+() const + constexpr Self operator+() const { static_assert(Arith, "'+a' is only available for DistinctNumeric types with 'Arith'."); return +this->m_value; } - Self operator-() const + constexpr Self operator-() const { static_assert(Arith, "'-a' is only available for DistinctNumeric types with 'Arith'."); return -this->m_value; } - Self operator*(const Self& other) const + constexpr Self operator*(const Self& other) const { static_assert(Arith, "'a*b' is only available for DistinctNumeric types with 'Arith'."); return this->m_value * other.m_value; } - Self operator/(const Self& other) const + constexpr Self operator/(const Self& other) const { static_assert(Arith, "'a/b' is only available for DistinctNumeric types with 'Arith'."); return this->m_value / other.m_value; } - Self operator%(const Self& other) const + constexpr Self operator%(const Self& other) const { static_assert(Arith, "'a%b' is only available for DistinctNumeric types with 'Arith'."); return this->m_value % other.m_value; } - Self& operator+=(const Self& other) + constexpr Self& operator+=(const Self& other) { static_assert(Arith, "'a+=b' is only available for DistinctNumeric types with 'Arith'."); this->m_value += other.m_value; return *this; } - Self& operator-=(const Self& other) + constexpr Self& operator-=(const Self& other) { static_assert(Arith, "'a+=b' is only available for DistinctNumeric types with 'Arith'."); this->m_value += other.m_value; return *this; } - Self& operator*=(const Self& other) + constexpr Self& operator*=(const Self& other) { static_assert(Arith, "'a*=b' is only available for DistinctNumeric types with 'Arith'."); this->m_value *= other.m_value; return *this; } - Self& operator/=(const Self& other) + constexpr Self& operator/=(const Self& other) { static_assert(Arith, "'a/=b' is only available for DistinctNumeric types with 'Arith'."); this->m_value /= other.m_value; return *this; } - Self& operator%=(const Self& other) + constexpr Self& operator%=(const Self& other) { static_assert(Arith, "'a%=b' is only available for DistinctNumeric types with 'Arith'."); this->m_value %= other.m_value;