fixed_point: Replace CONSTEXPR14 with constexpr

As we require the latest C++ standards to compile yuzu, checking for C++14 constexpr is not needed.
This commit is contained in:
Morph 2022-10-17 03:16:54 -04:00
parent bffbaddb79
commit 88ccdaf10a
1 changed files with 42 additions and 50 deletions

View File

@ -6,12 +6,6 @@
#pragma once #pragma once
#if __cplusplus >= 201402L
#define CONSTEXPR14 constexpr
#else
#define CONSTEXPR14
#endif
#include <cstddef> // for size_t #include <cstddef> // for size_t
#include <cstdint> #include <cstdint>
#include <exception> #include <exception>
@ -105,7 +99,7 @@ constexpr B next_to_base(N rhs) {
struct divide_by_zero : std::exception {}; struct divide_by_zero : std::exception {};
template <size_t I, size_t F> template <size_t I, size_t F>
CONSTEXPR14 FixedPoint<I, F> divide( constexpr FixedPoint<I, F> divide(
FixedPoint<I, F> numerator, FixedPoint<I, F> denominator, FixedPoint<I, F>& remainder, FixedPoint<I, F> numerator, FixedPoint<I, F> denominator, FixedPoint<I, F>& remainder,
typename std::enable_if<type_from_size<I + F>::next_size::is_specialized>::type* = nullptr) { typename std::enable_if<type_from_size<I + F>::next_size::is_specialized>::type* = nullptr) {
@ -125,7 +119,7 @@ CONSTEXPR14 FixedPoint<I, F> divide(
} }
template <size_t I, size_t F> template <size_t I, size_t F>
CONSTEXPR14 FixedPoint<I, F> divide( constexpr FixedPoint<I, F> divide(
FixedPoint<I, F> numerator, FixedPoint<I, F> denominator, FixedPoint<I, F>& remainder, FixedPoint<I, F> numerator, FixedPoint<I, F> denominator, FixedPoint<I, F>& remainder,
typename std::enable_if<!type_from_size<I + F>::next_size::is_specialized>::type* = nullptr) { typename std::enable_if<!type_from_size<I + F>::next_size::is_specialized>::type* = nullptr) {
@ -195,7 +189,7 @@ CONSTEXPR14 FixedPoint<I, F> divide(
// this is the usual implementation of multiplication // this is the usual implementation of multiplication
template <size_t I, size_t F> template <size_t I, size_t F>
CONSTEXPR14 FixedPoint<I, F> multiply( constexpr FixedPoint<I, F> multiply(
FixedPoint<I, F> lhs, FixedPoint<I, F> rhs, FixedPoint<I, F> lhs, FixedPoint<I, F> rhs,
typename std::enable_if<type_from_size<I + F>::next_size::is_specialized>::type* = nullptr) { typename std::enable_if<type_from_size<I + F>::next_size::is_specialized>::type* = nullptr) {
@ -214,7 +208,7 @@ CONSTEXPR14 FixedPoint<I, F> multiply(
// it is slightly slower, but is more robust since it doesn't // it is slightly slower, but is more robust since it doesn't
// require and upgraded type // require and upgraded type
template <size_t I, size_t F> template <size_t I, size_t F>
CONSTEXPR14 FixedPoint<I, F> multiply( constexpr FixedPoint<I, F> multiply(
FixedPoint<I, F> lhs, FixedPoint<I, F> rhs, FixedPoint<I, F> lhs, FixedPoint<I, F> rhs,
typename std::enable_if<!type_from_size<I + F>::next_size::is_specialized>::type* = nullptr) { typename std::enable_if<!type_from_size<I + F>::next_size::is_specialized>::type* = nullptr) {
@ -283,7 +277,7 @@ public: // constructors
public: // conversion public: // conversion
template <size_t I2, size_t F2> template <size_t I2, size_t F2>
CONSTEXPR14 explicit FixedPoint(FixedPoint<I2, F2> other) { constexpr explicit FixedPoint(FixedPoint<I2, F2> other) {
static_assert(I2 <= I && F2 <= F, "Scaling conversion can only upgrade types"); static_assert(I2 <= I && F2 <= F, "Scaling conversion can only upgrade types");
using T = FixedPoint<I2, F2>; using T = FixedPoint<I2, F2>;
@ -352,81 +346,81 @@ public: // unary operators
return FixedPoint::from_base(+data_); return FixedPoint::from_base(+data_);
} }
CONSTEXPR14 FixedPoint& operator++() { constexpr FixedPoint& operator++() {
data_ += one; data_ += one;
return *this; return *this;
} }
CONSTEXPR14 FixedPoint& operator--() { constexpr FixedPoint& operator--() {
data_ -= one; data_ -= one;
return *this; return *this;
} }
CONSTEXPR14 FixedPoint operator++(int) { constexpr FixedPoint operator++(int) {
FixedPoint tmp(*this); FixedPoint tmp(*this);
data_ += one; data_ += one;
return tmp; return tmp;
} }
CONSTEXPR14 FixedPoint operator--(int) { constexpr FixedPoint operator--(int) {
FixedPoint tmp(*this); FixedPoint tmp(*this);
data_ -= one; data_ -= one;
return tmp; return tmp;
} }
public: // basic math operators public: // basic math operators
CONSTEXPR14 FixedPoint& operator+=(FixedPoint n) { constexpr FixedPoint& operator+=(FixedPoint n) {
data_ += n.data_; data_ += n.data_;
return *this; return *this;
} }
CONSTEXPR14 FixedPoint& operator-=(FixedPoint n) { constexpr FixedPoint& operator-=(FixedPoint n) {
data_ -= n.data_; data_ -= n.data_;
return *this; return *this;
} }
CONSTEXPR14 FixedPoint& operator*=(FixedPoint n) { constexpr FixedPoint& operator*=(FixedPoint n) {
return assign(detail::multiply(*this, n)); return assign(detail::multiply(*this, n));
} }
CONSTEXPR14 FixedPoint& operator/=(FixedPoint n) { constexpr FixedPoint& operator/=(FixedPoint n) {
FixedPoint temp; FixedPoint temp;
return assign(detail::divide(*this, n, temp)); return assign(detail::divide(*this, n, temp));
} }
private: private:
CONSTEXPR14 FixedPoint& assign(FixedPoint rhs) { constexpr FixedPoint& assign(FixedPoint rhs) {
data_ = rhs.data_; data_ = rhs.data_;
return *this; return *this;
} }
public: // binary math operators, effects underlying bit pattern since these public: // binary math operators, effects underlying bit pattern since these
// don't really typically make sense for non-integer values // don't really typically make sense for non-integer values
CONSTEXPR14 FixedPoint& operator&=(FixedPoint n) { constexpr FixedPoint& operator&=(FixedPoint n) {
data_ &= n.data_; data_ &= n.data_;
return *this; return *this;
} }
CONSTEXPR14 FixedPoint& operator|=(FixedPoint n) { constexpr FixedPoint& operator|=(FixedPoint n) {
data_ |= n.data_; data_ |= n.data_;
return *this; return *this;
} }
CONSTEXPR14 FixedPoint& operator^=(FixedPoint n) { constexpr FixedPoint& operator^=(FixedPoint n) {
data_ ^= n.data_; data_ ^= n.data_;
return *this; return *this;
} }
template <class Integer, template <class Integer,
class = typename std::enable_if<std::is_integral<Integer>::value>::type> class = typename std::enable_if<std::is_integral<Integer>::value>::type>
CONSTEXPR14 FixedPoint& operator>>=(Integer n) { constexpr FixedPoint& operator>>=(Integer n) {
data_ >>= n; data_ >>= n;
return *this; return *this;
} }
template <class Integer, template <class Integer,
class = typename std::enable_if<std::is_integral<Integer>::value>::type> class = typename std::enable_if<std::is_integral<Integer>::value>::type>
CONSTEXPR14 FixedPoint& operator<<=(Integer n) { constexpr FixedPoint& operator<<=(Integer n) {
data_ <<= n; data_ <<= n;
return *this; return *this;
} }
@ -484,7 +478,7 @@ public: // conversion to basic types
} }
public: public:
CONSTEXPR14 void swap(FixedPoint& rhs) { constexpr void swap(FixedPoint& rhs) {
using std::swap; using std::swap;
swap(data_, rhs.data_); swap(data_, rhs.data_);
} }
@ -496,8 +490,8 @@ public:
// if we have the same fractional portion, but differing integer portions, we trivially upgrade the // if we have the same fractional portion, but differing integer portions, we trivially upgrade the
// smaller type // smaller type
template <size_t I1, size_t I2, size_t F> template <size_t I1, size_t I2, size_t F>
CONSTEXPR14 typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type constexpr typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type operator+(
operator+(FixedPoint<I1, F> lhs, FixedPoint<I2, F> rhs) { FixedPoint<I1, F> lhs, FixedPoint<I2, F> rhs) {
using T = typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type; using T = typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type;
@ -507,8 +501,8 @@ operator+(FixedPoint<I1, F> lhs, FixedPoint<I2, F> rhs) {
} }
template <size_t I1, size_t I2, size_t F> template <size_t I1, size_t I2, size_t F>
CONSTEXPR14 typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type constexpr typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type operator-(
operator-(FixedPoint<I1, F> lhs, FixedPoint<I2, F> rhs) { FixedPoint<I1, F> lhs, FixedPoint<I2, F> rhs) {
using T = typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type; using T = typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type;
@ -518,8 +512,8 @@ operator-(FixedPoint<I1, F> lhs, FixedPoint<I2, F> rhs) {
} }
template <size_t I1, size_t I2, size_t F> template <size_t I1, size_t I2, size_t F>
CONSTEXPR14 typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type constexpr typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type operator*(
operator*(FixedPoint<I1, F> lhs, FixedPoint<I2, F> rhs) { FixedPoint<I1, F> lhs, FixedPoint<I2, F> rhs) {
using T = typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type; using T = typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type;
@ -529,8 +523,8 @@ operator*(FixedPoint<I1, F> lhs, FixedPoint<I2, F> rhs) {
} }
template <size_t I1, size_t I2, size_t F> template <size_t I1, size_t I2, size_t F>
CONSTEXPR14 typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type constexpr typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type operator/(
operator/(FixedPoint<I1, F> lhs, FixedPoint<I2, F> rhs) { FixedPoint<I1, F> lhs, FixedPoint<I2, F> rhs) {
using T = typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type; using T = typename std::conditional<I1 >= I2, FixedPoint<I1, F>, FixedPoint<I2, F>>::type;
@ -547,75 +541,75 @@ std::ostream& operator<<(std::ostream& os, FixedPoint<I, F> f) {
// basic math operators // basic math operators
template <size_t I, size_t F> template <size_t I, size_t F>
CONSTEXPR14 FixedPoint<I, F> operator+(FixedPoint<I, F> lhs, FixedPoint<I, F> rhs) { constexpr FixedPoint<I, F> operator+(FixedPoint<I, F> lhs, FixedPoint<I, F> rhs) {
lhs += rhs; lhs += rhs;
return lhs; return lhs;
} }
template <size_t I, size_t F> template <size_t I, size_t F>
CONSTEXPR14 FixedPoint<I, F> operator-(FixedPoint<I, F> lhs, FixedPoint<I, F> rhs) { constexpr FixedPoint<I, F> operator-(FixedPoint<I, F> lhs, FixedPoint<I, F> rhs) {
lhs -= rhs; lhs -= rhs;
return lhs; return lhs;
} }
template <size_t I, size_t F> template <size_t I, size_t F>
CONSTEXPR14 FixedPoint<I, F> operator*(FixedPoint<I, F> lhs, FixedPoint<I, F> rhs) { constexpr FixedPoint<I, F> operator*(FixedPoint<I, F> lhs, FixedPoint<I, F> rhs) {
lhs *= rhs; lhs *= rhs;
return lhs; return lhs;
} }
template <size_t I, size_t F> template <size_t I, size_t F>
CONSTEXPR14 FixedPoint<I, F> operator/(FixedPoint<I, F> lhs, FixedPoint<I, F> rhs) { constexpr FixedPoint<I, F> operator/(FixedPoint<I, F> lhs, FixedPoint<I, F> rhs) {
lhs /= rhs; lhs /= rhs;
return lhs; return lhs;
} }
template <size_t I, size_t F, class Number, template <size_t I, size_t F, class Number,
class = typename std::enable_if<std::is_arithmetic<Number>::value>::type> class = typename std::enable_if<std::is_arithmetic<Number>::value>::type>
CONSTEXPR14 FixedPoint<I, F> operator+(FixedPoint<I, F> lhs, Number rhs) { constexpr FixedPoint<I, F> operator+(FixedPoint<I, F> lhs, Number rhs) {
lhs += FixedPoint<I, F>(rhs); lhs += FixedPoint<I, F>(rhs);
return lhs; return lhs;
} }
template <size_t I, size_t F, class Number, template <size_t I, size_t F, class Number,
class = typename std::enable_if<std::is_arithmetic<Number>::value>::type> class = typename std::enable_if<std::is_arithmetic<Number>::value>::type>
CONSTEXPR14 FixedPoint<I, F> operator-(FixedPoint<I, F> lhs, Number rhs) { constexpr FixedPoint<I, F> operator-(FixedPoint<I, F> lhs, Number rhs) {
lhs -= FixedPoint<I, F>(rhs); lhs -= FixedPoint<I, F>(rhs);
return lhs; return lhs;
} }
template <size_t I, size_t F, class Number, template <size_t I, size_t F, class Number,
class = typename std::enable_if<std::is_arithmetic<Number>::value>::type> class = typename std::enable_if<std::is_arithmetic<Number>::value>::type>
CONSTEXPR14 FixedPoint<I, F> operator*(FixedPoint<I, F> lhs, Number rhs) { constexpr FixedPoint<I, F> operator*(FixedPoint<I, F> lhs, Number rhs) {
lhs *= FixedPoint<I, F>(rhs); lhs *= FixedPoint<I, F>(rhs);
return lhs; return lhs;
} }
template <size_t I, size_t F, class Number, template <size_t I, size_t F, class Number,
class = typename std::enable_if<std::is_arithmetic<Number>::value>::type> class = typename std::enable_if<std::is_arithmetic<Number>::value>::type>
CONSTEXPR14 FixedPoint<I, F> operator/(FixedPoint<I, F> lhs, Number rhs) { constexpr FixedPoint<I, F> operator/(FixedPoint<I, F> lhs, Number rhs) {
lhs /= FixedPoint<I, F>(rhs); lhs /= FixedPoint<I, F>(rhs);
return lhs; return lhs;
} }
template <size_t I, size_t F, class Number, template <size_t I, size_t F, class Number,
class = typename std::enable_if<std::is_arithmetic<Number>::value>::type> class = typename std::enable_if<std::is_arithmetic<Number>::value>::type>
CONSTEXPR14 FixedPoint<I, F> operator+(Number lhs, FixedPoint<I, F> rhs) { constexpr FixedPoint<I, F> operator+(Number lhs, FixedPoint<I, F> rhs) {
FixedPoint<I, F> tmp(lhs); FixedPoint<I, F> tmp(lhs);
tmp += rhs; tmp += rhs;
return tmp; return tmp;
} }
template <size_t I, size_t F, class Number, template <size_t I, size_t F, class Number,
class = typename std::enable_if<std::is_arithmetic<Number>::value>::type> class = typename std::enable_if<std::is_arithmetic<Number>::value>::type>
CONSTEXPR14 FixedPoint<I, F> operator-(Number lhs, FixedPoint<I, F> rhs) { constexpr FixedPoint<I, F> operator-(Number lhs, FixedPoint<I, F> rhs) {
FixedPoint<I, F> tmp(lhs); FixedPoint<I, F> tmp(lhs);
tmp -= rhs; tmp -= rhs;
return tmp; return tmp;
} }
template <size_t I, size_t F, class Number, template <size_t I, size_t F, class Number,
class = typename std::enable_if<std::is_arithmetic<Number>::value>::type> class = typename std::enable_if<std::is_arithmetic<Number>::value>::type>
CONSTEXPR14 FixedPoint<I, F> operator*(Number lhs, FixedPoint<I, F> rhs) { constexpr FixedPoint<I, F> operator*(Number lhs, FixedPoint<I, F> rhs) {
FixedPoint<I, F> tmp(lhs); FixedPoint<I, F> tmp(lhs);
tmp *= rhs; tmp *= rhs;
return tmp; return tmp;
} }
template <size_t I, size_t F, class Number, template <size_t I, size_t F, class Number,
class = typename std::enable_if<std::is_arithmetic<Number>::value>::type> class = typename std::enable_if<std::is_arithmetic<Number>::value>::type>
CONSTEXPR14 FixedPoint<I, F> operator/(Number lhs, FixedPoint<I, F> rhs) { constexpr FixedPoint<I, F> operator/(Number lhs, FixedPoint<I, F> rhs) {
FixedPoint<I, F> tmp(lhs); FixedPoint<I, F> tmp(lhs);
tmp /= rhs; tmp /= rhs;
return tmp; return tmp;
@ -624,13 +618,13 @@ CONSTEXPR14 FixedPoint<I, F> operator/(Number lhs, FixedPoint<I, F> rhs) {
// shift operators // shift operators
template <size_t I, size_t F, class Integer, template <size_t I, size_t F, class Integer,
class = typename std::enable_if<std::is_integral<Integer>::value>::type> class = typename std::enable_if<std::is_integral<Integer>::value>::type>
CONSTEXPR14 FixedPoint<I, F> operator<<(FixedPoint<I, F> lhs, Integer rhs) { constexpr FixedPoint<I, F> operator<<(FixedPoint<I, F> lhs, Integer rhs) {
lhs <<= rhs; lhs <<= rhs;
return lhs; return lhs;
} }
template <size_t I, size_t F, class Integer, template <size_t I, size_t F, class Integer,
class = typename std::enable_if<std::is_integral<Integer>::value>::type> class = typename std::enable_if<std::is_integral<Integer>::value>::type>
CONSTEXPR14 FixedPoint<I, F> operator>>(FixedPoint<I, F> lhs, Integer rhs) { constexpr FixedPoint<I, F> operator>>(FixedPoint<I, F> lhs, Integer rhs) {
lhs >>= rhs; lhs >>= rhs;
return lhs; return lhs;
} }
@ -699,5 +693,3 @@ constexpr bool operator!=(Number lhs, FixedPoint<I, F> rhs) {
} }
} // namespace Common } // namespace Common
#undef CONSTEXPR14