From 655beda5bda9b41dc21ee9cef422faa6f92d9f27 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 2 Mar 2020 07:55:59 +0100 Subject: [PATCH] =?UTF-8?q?It=E2=80=99s=202020,=20use=20[[nodiscard]]=20un?= =?UTF-8?q?conditionally.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/lol/base/core.h | 8 +++ include/lol/base/pegtl.h | 7 +++ include/lol/base/private/features.h | 12 ++--- include/lol/math/polynomial.h | 8 +-- include/lol/math/private/matrix.h | 18 +++---- include/lol/math/private/ops.h | 8 +-- include/lol/math/rand.h | 28 +++++----- include/lol/math/real.h | 40 +++++++------- include/lol/math/transform.h | 32 +++++------ include/lol/math/vector.h | 22 ++++---- legacy/lol/math/arraynd.h | 2 +- legacy/lol/math/bigint.h | 2 +- legacy/lol/math/functions.h | 84 ++++++++++++++--------------- legacy/lol/math/geometry.h | 30 +++++------ legacy/lol/math/half.h | 58 ++++++++++---------- 15 files changed, 183 insertions(+), 176 deletions(-) diff --git a/include/lol/base/core.h b/include/lol/base/core.h index 807cb1a7..0e99cb8f 100644 --- a/include/lol/base/core.h +++ b/include/lol/base/core.h @@ -39,6 +39,14 @@ static inline std::string getenv(std::string const &var) return std::string(); } +// A handy endianness test function +static inline bool is_big_endian() +{ + union { int i; char c; } u; + u.i = 1; + return u.c == 0; +} + } // namespace os } // namespace lol diff --git a/include/lol/base/pegtl.h b/include/lol/base/pegtl.h index e85274e4..2df72784 100644 --- a/include/lol/base/pegtl.h +++ b/include/lol/base/pegtl.h @@ -17,6 +17,13 @@ // ————————————————— // +// Ensure CreateFile2() is available on mingw +#if defined _WIN32 && !defined _MSC_VER && \ + (!defined _WIN32_WINNT || _WIN32_WINNT < 0x0602) +# undef _WIN32_WINNT +# define _WIN32_WINNT 0x0602 +#endif + //namespace lol //{ diff --git a/include/lol/base/private/features.h b/include/lol/base/private/features.h index de0c4d29..22fc4a23 100644 --- a/include/lol/base/private/features.h +++ b/include/lol/base/private/features.h @@ -19,16 +19,12 @@ // C++ compiler features detected through __has_cpp_attribute -#if defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard) -# define lol_attr_nodiscard [[nodiscard]] -#else -# define lol_attr_nodiscard /* */ +#if defined(__has_cpp_attribute) && !__has_cpp_attribute(nodiscard) +# error C++ compiler support for [[nodiscard]] is required (use -std=c++17?) #endif -#if defined(__has_cpp_attribute) && __has_cpp_attribute(fallthrough) -# define LOL_ATTR_FALLTHROUGH [[fallthrough]]; -#else -# define LOL_ATTR_FALLTHROUGH /* */ +#if defined(__has_cpp_attribute) && !__has_cpp_attribute(fallthrough) +# error C++ compiler support for [[fallthrough]] is required (use -std=c++17?) #endif // Define some attribute macros. diff --git a/include/lol/math/polynomial.h b/include/lol/math/polynomial.h index aad91347..77eb6512 100644 --- a/include/lol/math/polynomial.h +++ b/include/lol/math/polynomial.h @@ -30,7 +30,7 @@ namespace lol { template -struct lol_attr_nodiscard polynomial +struct [[nodiscard]] polynomial { /* The zero polynomial */ explicit inline polynomial() {} @@ -95,7 +95,7 @@ struct lol_attr_nodiscard polynomial /* Evaluate polynomial at a given value. This method can also * be used to compose polynomials, i.e. using another polynomial * as the value instead of a scalar. */ - template lol_attr_nodiscard U eval(U x) const + template [[nodiscard]] U eval(U x) const { U ret(leading()); for (int i = degree() - 1; i >= 0; --i) @@ -264,7 +264,7 @@ struct lol_attr_nodiscard polynomial * copy because we cannot let the user mess with the integrity of * the structure (i.e. the guarantee that the leading coefficient * remains non-zero). */ - lol_attr_nodiscard inline T operator[](ptrdiff_t n) const + [[nodiscard]] inline T operator[](ptrdiff_t n) const { if (n < 0 || n > degree()) return T(0); @@ -273,7 +273,7 @@ struct lol_attr_nodiscard polynomial } /* Return the leading coefficient */ - lol_attr_nodiscard inline T leading() const + [[nodiscard]] inline T leading() const { return (*this)[degree()]; } diff --git a/include/lol/math/private/matrix.h b/include/lol/math/private/matrix.h index e1606cf1..e0806f5d 100644 --- a/include/lol/math/private/matrix.h +++ b/include/lol/math/private/matrix.h @@ -39,7 +39,7 @@ namespace lol */ template -struct lol_attr_nodiscard mat_t +struct [[nodiscard]] mat_t : public linear_ops::base> { static int const count = COLS; @@ -77,7 +77,7 @@ private: */ template -struct lol_attr_nodiscard mat_t +struct [[nodiscard]] mat_t : public linear_ops::base> { static int const count = 2; @@ -129,7 +129,7 @@ static_assert(sizeof(dmat2) == 32, "sizeof(dmat2) == 32"); */ template -struct lol_attr_nodiscard mat_t +struct [[nodiscard]] mat_t : public linear_ops::base> { static int const count = 3; @@ -220,7 +220,7 @@ static_assert(sizeof(dmat3) == 72, "sizeof(dmat3) == 72"); */ template -struct lol_attr_nodiscard mat_t +struct [[nodiscard]] mat_t : public linear_ops::base> { static int const count = 4; @@ -402,7 +402,7 @@ mat_t submatrix(mat_t const &m, int i, int j) * Compute square matrix cofactor */ -template lol_attr_nodiscard +template [[nodiscard]] T cofactor(mat_t const &m, int i, int j) { ASSERT(i >= 0); ASSERT(j >= 0); ASSERT(i < N); ASSERT(j < N); @@ -410,7 +410,7 @@ T cofactor(mat_t const &m, int i, int j) return ((i + j) & 1) ? -tmp : tmp; } -template lol_attr_nodiscard +template [[nodiscard]] T cofactor(mat_t const &m, int i, int j) { /* This specialisation shouldn't be needed, but Visual Studio. */ @@ -420,7 +420,7 @@ T cofactor(mat_t const &m, int i, int j) } // Lu decomposition with partial pivoting -template lol_attr_nodiscard +template [[nodiscard]] std::tuple, vec_t, int> lu_decomposition(mat_t const &m) { mat_t lu = m; @@ -463,7 +463,7 @@ std::tuple, vec_t, int> lu_decomposition(mat_t c * Compute square matrix determinant, with a specialisation for 1×1 matrices */ -template lol_attr_nodiscard +template [[nodiscard]] T determinant(mat_t const &m) { auto lup = lu_decomposition(m); @@ -475,7 +475,7 @@ T determinant(mat_t const &m) return det; } -template lol_attr_nodiscard +template [[nodiscard]] T const & determinant(mat_t const &m) { return m[0][0]; diff --git a/include/lol/math/private/ops.h b/include/lol/math/private/ops.h index 5e480f99..c7c9affe 100644 --- a/include/lol/math/private/ops.h +++ b/include/lol/math/private/ops.h @@ -71,14 +71,14 @@ namespace swizzle_ops namespace swizzle_ops { -template lol_attr_nodiscard +template [[nodiscard]] static inline typename std::enable_if::type operator ==(vec_t const &a, vec_t const &b) { return vec_t(a) == vec_t(b); } -template lol_attr_nodiscard +template [[nodiscard]] static inline typename std::enable_if::type operator !=(vec_t const &a, vec_t const &b) { @@ -136,7 +136,7 @@ namespace linear_ops * Comparisons */ -template lol_attr_nodiscard +template [[nodiscard]] static inline typename std::enable_if, V>::value, bool>::type operator ==(V const &a, V const &b) { @@ -146,7 +146,7 @@ operator ==(V const &a, V const &b) return true; } -template lol_attr_nodiscard +template [[nodiscard]] static inline typename std::enable_if, V>::value, bool>::type operator !=(V const &a, V const &b) { diff --git a/include/lol/math/rand.h b/include/lol/math/rand.h index d42e5d28..2f86ac76 100644 --- a/include/lol/math/rand.h +++ b/include/lol/math/rand.h @@ -27,50 +27,50 @@ namespace lol { /* Random number generators */ -template lol_attr_nodiscard static inline T rand(); -template lol_attr_nodiscard static inline T rand(T a); -template lol_attr_nodiscard static inline T rand(T a, T b); +template [[nodiscard]] static inline T rand(); +template [[nodiscard]] static inline T rand(T a); +template [[nodiscard]] static inline T rand(T a, T b); /* One-value random number generators */ -template lol_attr_nodiscard static inline T rand(T a) +template [[nodiscard]] static inline T rand(T a) { return a ? rand() % a : T(0); } #if 0 -template<> lol_attr_nodiscard inline half rand(half a) +template<> [[nodiscard]] inline half rand(half a) { float f = (float)std::rand() / (float)RAND_MAX; return (half)(a * f); } #endif -template<> lol_attr_nodiscard inline float rand(float a) +template<> [[nodiscard]] inline float rand(float a) { auto f = (float)std::rand() / (float)RAND_MAX; return a * f; } -template<> lol_attr_nodiscard inline double rand(double a) +template<> [[nodiscard]] inline double rand(double a) { auto f = (double)std::rand() / (double)RAND_MAX; return a * f; } -template<> lol_attr_nodiscard inline long double rand(long double a) +template<> [[nodiscard]] inline long double rand(long double a) { auto f = (long double)std::rand() / (long double)RAND_MAX; return a * f; } /* Two-value random number generator -- no need for specialisation */ -template lol_attr_nodiscard static inline T rand(T a, T b) +template [[nodiscard]] static inline T rand(T a, T b) { return a + rand(b - a); } /* Default random number generator */ -template lol_attr_nodiscard static inline T rand() +template [[nodiscard]] static inline T rand() { switch (sizeof(T)) { @@ -124,11 +124,11 @@ template lol_attr_nodiscard static inline T rand() } #if 0 -template<> lol_attr_nodiscard inline half rand() { return rand(1.f); } +template<> [[nodiscard]] inline half rand() { return rand(1.f); } #endif -template<> lol_attr_nodiscard inline float rand() { return rand(1.f); } -template<> lol_attr_nodiscard inline double rand() { return rand(1.0); } -template<> lol_attr_nodiscard inline long double rand() { return rand(1.0); } +template<> [[nodiscard]] inline float rand() { return rand(1.f); } +template<> [[nodiscard]] inline double rand() { return rand(1.0); } +template<> [[nodiscard]] inline long double rand() { return rand(1.0); } } /* namespace lol */ diff --git a/include/lol/math/real.h b/include/lol/math/real.h index a6b1d9a1..c996f449 100644 --- a/include/lol/math/real.h +++ b/include/lol/math/real.h @@ -41,7 +41,7 @@ namespace lol // call real::sqrt). // template -class lol_attr_nodiscard real_t +class [[nodiscard]] real_t { public: typedef T bigit_t; @@ -65,19 +65,19 @@ public: return n <= 0 ? count : (count = n); } - lol_attr_nodiscard bool is_zero() const { return m_mantissa.size() == 0; } - lol_attr_nodiscard bool is_negative() const { return m_sign; } - lol_attr_nodiscard bool is_nan() const { return m_nan; } - lol_attr_nodiscard bool is_inf() const { return m_inf; } + [[nodiscard]] bool is_zero() const { return m_mantissa.size() == 0; } + [[nodiscard]] bool is_negative() const { return m_sign; } + [[nodiscard]] bool is_nan() const { return m_nan; } + [[nodiscard]] bool is_inf() const { return m_inf; } // Mark all these operators explicit to avoid surprises - lol_attr_nodiscard explicit operator float() const; - lol_attr_nodiscard explicit operator double() const; - lol_attr_nodiscard explicit operator long double() const; - lol_attr_nodiscard explicit operator int32_t() const; - lol_attr_nodiscard explicit operator uint32_t() const; - lol_attr_nodiscard explicit operator int64_t() const; - lol_attr_nodiscard explicit operator uint64_t() const; + [[nodiscard]] explicit operator float() const; + [[nodiscard]] explicit operator double() const; + [[nodiscard]] explicit operator long double() const; + [[nodiscard]] explicit operator int32_t() const; + [[nodiscard]] explicit operator uint32_t() const; + [[nodiscard]] explicit operator int64_t() const; + [[nodiscard]] explicit operator uint64_t() const; real_t operator +() const; real_t operator -() const; @@ -90,15 +90,15 @@ public: real_t const &operator *=(real_t const &x); real_t const &operator /=(real_t const &x); - lol_attr_nodiscard bool operator ==(real_t const &x) const; - lol_attr_nodiscard bool operator !=(real_t const &x) const; - lol_attr_nodiscard bool operator <(real_t const &x) const; - lol_attr_nodiscard bool operator >(real_t const &x) const; - lol_attr_nodiscard bool operator <=(real_t const &x) const; - lol_attr_nodiscard bool operator >=(real_t const &x) const; + [[nodiscard]] bool operator ==(real_t const &x) const; + [[nodiscard]] bool operator !=(real_t const &x) const; + [[nodiscard]] bool operator <(real_t const &x) const; + [[nodiscard]] bool operator >(real_t const &x) const; + [[nodiscard]] bool operator <=(real_t const &x) const; + [[nodiscard]] bool operator >=(real_t const &x) const; - lol_attr_nodiscard bool operator !() const; - lol_attr_nodiscard explicit operator bool() const; + [[nodiscard]] bool operator !() const; + [[nodiscard]] explicit operator bool() const; // Comparison functions template friend real_t min(real_t const &a, diff --git a/include/lol/math/transform.h b/include/lol/math/transform.h index dde74f2b..1bdeebad 100644 --- a/include/lol/math/transform.h +++ b/include/lol/math/transform.h @@ -32,7 +32,7 @@ namespace lol */ template -struct lol_attr_nodiscard cmplx_t : public linear_ops::base +struct [[nodiscard]] cmplx_t : public linear_ops::base { static int const count = 2; typedef T scalar_element; @@ -80,7 +80,7 @@ static_assert(sizeof(dcmplx) == 16, "sizeof(dcmplx) == 16"); */ template -struct lol_attr_nodiscard quat_t : public linear_ops::base +struct [[nodiscard]] quat_t : public linear_ops::base { static int const count = 4; typedef T scalar_element; @@ -234,7 +234,7 @@ struct lol_attr_nodiscard quat_t : public linear_ops::base return normalize(v); } - lol_attr_nodiscard inline T angle() + [[nodiscard]] inline T angle() { vec_t v(x, y, z); T n2 = sqlength(v); @@ -259,7 +259,7 @@ static_assert(sizeof(dquat) == 32, "sizeof(dquat) == 32"); */ template -struct lol_attr_nodiscard sqt_t +struct [[nodiscard]] sqt_t { /* Default constructor and copy constructor */ inline constexpr sqt_t() = default; @@ -343,7 +343,7 @@ std::ostream &operator<<(std::ostream &stream, quat_t const &q) * Common operations on transforms */ -template lol_attr_nodiscard +template [[nodiscard]] static inline T dot(cmplx_t const &t1, cmplx_t const &t2) { T ret(0); @@ -352,20 +352,20 @@ static inline T dot(cmplx_t const &t1, cmplx_t const &t2) return ret; } -template lol_attr_nodiscard +template [[nodiscard]] static inline T sqlength(cmplx_t const &t) { return dot(t, t); } -template lol_attr_nodiscard +template [[nodiscard]] static inline T length(cmplx_t const &t) { /* FIXME: this is not very nice */ return (T)sqrt((double)sqlength(t)); } -template lol_attr_nodiscard +template [[nodiscard]] static inline T norm(cmplx_t const &t) { return length(t); @@ -380,7 +380,7 @@ static inline cmplx_t normalize(cmplx_t const &z) /* XXX: duplicate */ -template lol_attr_nodiscard +template [[nodiscard]] static inline T dot(quat_t const &t1, quat_t const &t2) { T ret(0); @@ -389,20 +389,20 @@ static inline T dot(quat_t const &t1, quat_t const &t2) return ret; } -template lol_attr_nodiscard +template [[nodiscard]] static inline T sqlength(quat_t const &t) { return dot(t, t); } -template lol_attr_nodiscard +template [[nodiscard]] static inline T length(quat_t const &t) { /* FIXME: this is not very nice */ return (T)sqrt((double)sqlength(t)); } -template lol_attr_nodiscard +template [[nodiscard]] static inline T norm(quat_t const &t) { return length(t); @@ -437,22 +437,22 @@ static inline cmplx_t operator /(cmplx_t a, cmplx_t const &b) return a * inverse(b); } -template lol_attr_nodiscard +template [[nodiscard]] static inline bool operator ==(cmplx_t const &a, T b) { return (a.x == b) && !a.y; } -template lol_attr_nodiscard +template [[nodiscard]] static inline bool operator !=(cmplx_t const &a, T b) { return (a.x != b) || a.y; } -template lol_attr_nodiscard +template [[nodiscard]] static inline bool operator ==(T a, cmplx_t const &b) { return b == a; } -template lol_attr_nodiscard +template [[nodiscard]] static inline bool operator !=(T a, cmplx_t const &b) { return b != a; } /* diff --git a/include/lol/math/vector.h b/include/lol/math/vector.h index e49cb303..bd9bad3c 100644 --- a/include/lol/math/vector.h +++ b/include/lol/math/vector.h @@ -44,7 +44,7 @@ namespace lol */ template -struct lol_attr_nodiscard vec_t +struct [[nodiscard]] vec_t /* MUST have a different base than e.g. vec_t otherwise the unions * in vec_t with the same base will cause empty base optimisation * failures. */ @@ -114,7 +114,7 @@ private: /* The generic “vec_t” type, which is a fixed-size vector with no * swizzling. There's an override for N=2, N=3, N=4 that has swizzling. */ template -struct lol_attr_nodiscard vec_t +struct [[nodiscard]] vec_t : public componentwise_ops::base { static int const count = N; @@ -131,13 +131,9 @@ struct lol_attr_nodiscard vec_t /* Explicit constructor that takes exactly N arguments thanks to SFINAE. */ template -#if LOL_FEATURE_CXX11_SFINAE_FOR_CTORS explicit inline vec_t(T const &X, typename std::enable_if::type const &Y, ARGS... args) -#else - explicit inline vec_t(T const &X, T const &Y, ARGS... args) -#endif { static_assert(sizeof...(ARGS) + 2 == N, "wrong argument count in vec_t constructor"); @@ -203,7 +199,7 @@ private: */ template -struct lol_attr_nodiscard vec_t +struct [[nodiscard]] vec_t : public swizzle_ops::base { static int const count = 2; @@ -314,7 +310,7 @@ static_assert(sizeof(dvec2) == 16, "sizeof(dvec2) == 16"); */ template -struct lol_attr_nodiscard vec_t +struct [[nodiscard]] vec_t : public swizzle_ops::base { static int const count = 3; @@ -555,7 +551,7 @@ static_assert(sizeof(dvec3) == 24, "sizeof(dvec3) == 24"); */ template -struct lol_attr_nodiscard vec_t +struct [[nodiscard]] vec_t : public swizzle_ops::base { static int const count = 4; @@ -1117,7 +1113,7 @@ static inline vec_t mix(vec_t const &x, * Some GLSL-like functions. */ -template lol_attr_nodiscard +template [[nodiscard]] static inline T dot(vec_t const &a, vec_t const &b) { @@ -1127,13 +1123,13 @@ static inline T dot(vec_t const &a, return ret; } -template lol_attr_nodiscard +template [[nodiscard]] static inline T sqlength(vec_t const &a) { return dot(a, a); } -template lol_attr_nodiscard +template [[nodiscard]] static inline T length(vec_t const &a) { /* FIXME: this is not very nice */ @@ -1151,7 +1147,7 @@ static inline vec_t lerp(vec_t const &a, return ret; } -template lol_attr_nodiscard +template [[nodiscard]] static inline T distance(vec_t const &a, vec_t const &b) { diff --git a/legacy/lol/math/arraynd.h b/legacy/lol/math/arraynd.h index b141baf2..5e126257 100644 --- a/legacy/lol/math/arraynd.h +++ b/legacy/lol/math/arraynd.h @@ -96,7 +96,7 @@ private: template -class lol_attr_nodiscard arraynd : protected array +class [[nodiscard]] arraynd : protected array { public: typedef array super; diff --git a/legacy/lol/math/bigint.h b/legacy/lol/math/bigint.h index a914b420..533a1edc 100644 --- a/legacy/lol/math/bigint.h +++ b/legacy/lol/math/bigint.h @@ -37,7 +37,7 @@ namespace lol */ template -class lol_attr_nodiscard bigint +class [[nodiscard]] bigint { static int const bits_per_digit = sizeof(T) * 8 - 1; static T const digit_mask = ~((T)1 << bits_per_digit); diff --git a/legacy/lol/math/functions.h b/legacy/lol/math/functions.h index 442eb717..68207b36 100644 --- a/legacy/lol/math/functions.h +++ b/legacy/lol/math/functions.h @@ -44,15 +44,15 @@ namespace lol // Mechanism to import standard cmath functions #define LOL_FORWARD_FP_1_ARG(f) \ template \ - lol_attr_nodiscard static inline T2 f(T x) { return std::f(x); } + [[nodiscard]] static inline T2 f(T x) { return std::f(x); } #define LOL_FORWARD_ARITH_2_ARGS(f) \ template \ - lol_attr_nodiscard static inline T2 f(T x, T y) { return std::f(x, y); } + [[nodiscard]] static inline T2 f(T x, T y) { return std::f(x, y); } #define LOL_FORWARD_FP_2_ARGS(f) \ template \ - lol_attr_nodiscard static inline T2 f(T x, T y) { return std::f(x, y); } + [[nodiscard]] static inline T2 f(T x, T y) { return std::f(x, y); } LOL_FORWARD_FP_1_ARG(sqrt) LOL_FORWARD_FP_1_ARG(cbrt) @@ -78,72 +78,72 @@ LOL_FORWARD_FP_1_ARG(round) // Our extensions template -lol_attr_nodiscard static inline T2 sincos(T x, T *s, T *c) +[[nodiscard]] static inline T2 sincos(T x, T *s, T *c) { *s = std::sin(x); *c = std::cos(x); } // Inherited from GLSL -lol_attr_nodiscard static inline float degrees(float radians) +[[nodiscard]] static inline float degrees(float radians) { return radians * (180.0f / F_PI); } -lol_attr_nodiscard static inline double degrees(double radians) +[[nodiscard]] static inline double degrees(double radians) { return radians * (180.0 / D_PI); } -lol_attr_nodiscard static inline ldouble degrees(ldouble radians) +[[nodiscard]] static inline ldouble degrees(ldouble radians) { return radians * (180.0L / LD_PI); } -lol_attr_nodiscard static inline float radians(float degrees) +[[nodiscard]] static inline float radians(float degrees) { return degrees * (F_PI / 180.0f); } -lol_attr_nodiscard static inline double radians(double degrees) +[[nodiscard]] static inline double radians(double degrees) { return degrees * (D_PI / 180.0); } -lol_attr_nodiscard static inline ldouble radians(ldouble degrees) +[[nodiscard]] static inline ldouble radians(ldouble degrees) { return degrees * (LD_PI / 180.0L); } // The integer versions return floating point values. This avoids nasty // surprises when calling radians(180) instead of radians(180.0). -lol_attr_nodiscard static inline float degrees(int8_t x) { return degrees(float(x)); } -lol_attr_nodiscard static inline float degrees(uint8_t x) { return degrees(float(x)); } -lol_attr_nodiscard static inline float degrees(int16_t x) { return degrees(float(x)); } -lol_attr_nodiscard static inline float degrees(uint16_t x) { return degrees(float(x)); } -lol_attr_nodiscard static inline double degrees(int32_t x) { return degrees(double(x)); } -lol_attr_nodiscard static inline double degrees(uint32_t x) { return degrees(double(x)); } -lol_attr_nodiscard static inline ldouble degrees(int64_t x) { return degrees(ldouble(x)); } -lol_attr_nodiscard static inline ldouble degrees(uint64_t x) { return degrees(ldouble(x)); } - -lol_attr_nodiscard static inline float radians(int8_t x) { return radians(float(x)); } -lol_attr_nodiscard static inline float radians(uint8_t x) { return radians(float(x)); } -lol_attr_nodiscard static inline float radians(int16_t x) { return radians(float(x)); } -lol_attr_nodiscard static inline float radians(uint16_t x) { return radians(float(x)); } -lol_attr_nodiscard static inline double radians(int32_t x) { return radians(double(x)); } -lol_attr_nodiscard static inline double radians(uint32_t x) { return radians(double(x)); } -lol_attr_nodiscard static inline ldouble radians(int64_t x) { return radians(ldouble(x)); } -lol_attr_nodiscard static inline ldouble radians(uint64_t x) { return radians(ldouble(x)); } +[[nodiscard]] static inline float degrees(int8_t x) { return degrees(float(x)); } +[[nodiscard]] static inline float degrees(uint8_t x) { return degrees(float(x)); } +[[nodiscard]] static inline float degrees(int16_t x) { return degrees(float(x)); } +[[nodiscard]] static inline float degrees(uint16_t x) { return degrees(float(x)); } +[[nodiscard]] static inline double degrees(int32_t x) { return degrees(double(x)); } +[[nodiscard]] static inline double degrees(uint32_t x) { return degrees(double(x)); } +[[nodiscard]] static inline ldouble degrees(int64_t x) { return degrees(ldouble(x)); } +[[nodiscard]] static inline ldouble degrees(uint64_t x) { return degrees(ldouble(x)); } + +[[nodiscard]] static inline float radians(int8_t x) { return radians(float(x)); } +[[nodiscard]] static inline float radians(uint8_t x) { return radians(float(x)); } +[[nodiscard]] static inline float radians(int16_t x) { return radians(float(x)); } +[[nodiscard]] static inline float radians(uint16_t x) { return radians(float(x)); } +[[nodiscard]] static inline double radians(int32_t x) { return radians(double(x)); } +[[nodiscard]] static inline double radians(uint32_t x) { return radians(double(x)); } +[[nodiscard]] static inline ldouble radians(int64_t x) { return radians(ldouble(x)); } +[[nodiscard]] static inline ldouble radians(uint64_t x) { return radians(ldouble(x)); } template -lol_attr_nodiscard static inline T2 mix(T a, T b, T x) +[[nodiscard]] static inline T2 mix(T a, T b, T x) { return a + (b - a) * x; } // Inherited from HLSL template -lol_attr_nodiscard static inline T2 lerp(T a, T b, T x) +[[nodiscard]] static inline T2 lerp(T a, T b, T x) { return mix(a, b, x); } @@ -151,35 +151,35 @@ lol_attr_nodiscard static inline T2 lerp(T a, T b, T x) // C++ doesn't define abs() or fmod() for all types; we add these for // convenience to avoid adding complexity to vector.h. template -lol_attr_nodiscard static inline T2 abs(T x) { return std::abs(x); } +[[nodiscard]] static inline T2 abs(T x) { return std::abs(x); } template -lol_attr_nodiscard static inline T2 abs(T x) { return x; } +[[nodiscard]] static inline T2 abs(T x) { return x; } template -lol_attr_nodiscard static inline T2 fmod(T x, T y) { return x % y; } +[[nodiscard]] static inline T2 fmod(T x, T y) { return x % y; } template -lol_attr_nodiscard static inline T2 floor(T x) { return x; } +[[nodiscard]] static inline T2 floor(T x) { return x; } template -lol_attr_nodiscard static inline T2 ceil(T x) { return x; } +[[nodiscard]] static inline T2 ceil(T x) { return x; } template -lol_attr_nodiscard static inline T2 round(T x) { return x; } +[[nodiscard]] static inline T2 round(T x) { return x; } template -lol_attr_nodiscard static inline T2 sq(T x) { return x * x; } +[[nodiscard]] static inline T2 sq(T x) { return x * x; } template -lol_attr_nodiscard static inline T2 fract(T x) { return x - lol::floor(x); } +[[nodiscard]] static inline T2 fract(T x) { return x - lol::floor(x); } template -lol_attr_nodiscard static inline T2 clamp(T x, T y, T z) { return min(max(x, y), z); } +[[nodiscard]] static inline T2 clamp(T x, T y, T z) { return min(max(x, y), z); } template -lol_attr_nodiscard static inline T2 saturate(T x) { return clamp(x, (T)0, (T)1); } +[[nodiscard]] static inline T2 saturate(T x) { return clamp(x, (T)0, (T)1); } template -lol_attr_nodiscard static inline T2 gcd(T x, T y) { return y == (T)0 ? lol::abs(x) : lol::gcd(y, lol::fmod(x, y)); } +[[nodiscard]] static inline T2 gcd(T x, T y) { return y == (T)0 ? lol::abs(x) : lol::gcd(y, lol::fmod(x, y)); } template -lol_attr_nodiscard static inline T2 sign(T x) { return (T)(((T)0 < x) - (x < (T)0)); } +[[nodiscard]] static inline T2 sign(T x) { return (T)(((T)0 < x) - (x < (T)0)); } template -lol_attr_nodiscard static inline T2 sign(T x) { return (T)((T)0 < x); } +[[nodiscard]] static inline T2 sign(T x) { return (T)((T)0 < x); } } /* namespace lol */ diff --git a/legacy/lol/math/geometry.h b/legacy/lol/math/geometry.h index fef2023c..e5fe3588 100644 --- a/legacy/lol/math/geometry.h +++ b/legacy/lol/math/geometry.h @@ -91,7 +91,7 @@ T_(box_t<, C_ 4>, box4) #undef T_ template -struct lol_attr_nodiscard box_t +struct [[nodiscard]] box_t { inline box_t() : aa(vec_t(T(0))), @@ -154,12 +154,12 @@ struct lol_attr_nodiscard box_t return *this = *this * s; } - lol_attr_nodiscard bool operator ==(box_t const &box) const + [[nodiscard]] bool operator ==(box_t const &box) const { return aa == box.aa && bb == box.bb; } - lol_attr_nodiscard bool operator !=(box_t const &box) const + [[nodiscard]] bool operator !=(box_t const &box) const { return aa != box.aa || bb != box.bb; } @@ -193,19 +193,19 @@ private: float Minus() const; float Plus() const; public: - lol_attr_nodiscard bool operator==(float value) const; - lol_attr_nodiscard bool operator!=(float value) const; - lol_attr_nodiscard bool operator<(float value) const; - lol_attr_nodiscard bool operator<=(float value) const; - lol_attr_nodiscard bool operator>(float value) const; - lol_attr_nodiscard bool operator>=(float value) const; + [[nodiscard]] bool operator==(float value) const; + [[nodiscard]] bool operator!=(float value) const; + [[nodiscard]] bool operator<(float value) const; + [[nodiscard]] bool operator<=(float value) const; + [[nodiscard]] bool operator>(float value) const; + [[nodiscard]] bool operator>=(float value) const; }; -lol_attr_nodiscard bool operator==(float value, const TestEpsilon& epsilon); -lol_attr_nodiscard bool operator!=(float value, const TestEpsilon& epsilon); -lol_attr_nodiscard bool operator<(float value, const TestEpsilon& epsilon); -lol_attr_nodiscard bool operator<=(float value, const TestEpsilon& epsilon); -lol_attr_nodiscard bool operator>(float value, const TestEpsilon& epsilon); -lol_attr_nodiscard bool operator>=(float value, const TestEpsilon& epsilon); +[[nodiscard]] bool operator==(float value, const TestEpsilon& epsilon); +[[nodiscard]] bool operator!=(float value, const TestEpsilon& epsilon); +[[nodiscard]] bool operator<(float value, const TestEpsilon& epsilon); +[[nodiscard]] bool operator<=(float value, const TestEpsilon& epsilon); +[[nodiscard]] bool operator>(float value, const TestEpsilon& epsilon); +[[nodiscard]] bool operator>=(float value, const TestEpsilon& epsilon); //-- static inline bool TestAABBVsAABB(box2 const &b1, box2 const &b2) diff --git a/legacy/lol/math/half.h b/legacy/lol/math/half.h index 93335565..441e64b2 100644 --- a/legacy/lol/math/half.h +++ b/legacy/lol/math/half.h @@ -32,7 +32,7 @@ namespace lol namespace half_ops { struct base {}; } -class lol_attr_nodiscard half +class [[nodiscard]] half : half_ops::base { public: @@ -44,22 +44,22 @@ public: inline half(double f) { *this = makefast((float)f); } inline half(ldouble f) { *this = makefast((float)f); } - lol_attr_nodiscard inline int is_nan() const + [[nodiscard]] inline int is_nan() const { return ((bits & 0x7c00u) == 0x7c00u) && (bits & 0x03ffu); } - lol_attr_nodiscard inline int is_finite() const + [[nodiscard]] inline int is_finite() const { return (bits & 0x7c00u) != 0x7c00u; } - lol_attr_nodiscard inline int is_inf() const + [[nodiscard]] inline int is_inf() const { return (uint16_t)(bits << 1) == (0x7c00u << 1); } - lol_attr_nodiscard inline int is_normal() const + [[nodiscard]] inline int is_normal() const { return (is_finite() && (bits & 0x7c00u)) || ((bits & 0x7fffu) == 0); } @@ -69,33 +69,33 @@ public: inline half &operator =(float f) { return *this = makefast(f); } inline half &operator =(double f) { return *this = makefast((float)f); } inline half &operator =(ldouble f) { return *this = makefast((float)f); } - lol_attr_nodiscard inline operator int8_t() const { return (int8_t)(float)*this; } - lol_attr_nodiscard inline operator uint8_t() const { return (uint8_t)(float)*this; } - lol_attr_nodiscard inline operator int16_t() const { return (int16_t)(float)*this; } - lol_attr_nodiscard inline operator uint16_t() const { return (uint16_t)(float)*this; } - lol_attr_nodiscard inline operator int32_t() const { return (int32_t)(float)*this; } - lol_attr_nodiscard inline operator uint32_t() const { return (uint32_t)(float)*this; } - lol_attr_nodiscard inline operator int64_t() const { return (int64_t)(float)*this; } - lol_attr_nodiscard inline operator uint64_t() const { return (uint64_t)(float)*this; } - - lol_attr_nodiscard operator float() const; - lol_attr_nodiscard inline operator double() const { return (float)(*this); } - lol_attr_nodiscard inline operator ldouble() const { return (float)(*this); } + [[nodiscard]] inline operator int8_t() const { return (int8_t)(float)*this; } + [[nodiscard]] inline operator uint8_t() const { return (uint8_t)(float)*this; } + [[nodiscard]] inline operator int16_t() const { return (int16_t)(float)*this; } + [[nodiscard]] inline operator uint16_t() const { return (uint16_t)(float)*this; } + [[nodiscard]] inline operator int32_t() const { return (int32_t)(float)*this; } + [[nodiscard]] inline operator uint32_t() const { return (uint32_t)(float)*this; } + [[nodiscard]] inline operator int64_t() const { return (int64_t)(float)*this; } + [[nodiscard]] inline operator uint64_t() const { return (uint64_t)(float)*this; } + + [[nodiscard]] operator float() const; + [[nodiscard]] inline operator double() const { return (float)(*this); } + [[nodiscard]] inline operator ldouble() const { return (float)(*this); } /* Array conversions */ static void convert(half *dst, float const *src, size_t nelem); static void convert(float *dst, half const *src, size_t nelem); /* Operations */ - lol_attr_nodiscard bool operator ==(half x) const { return (float)*this == (float)x; } - lol_attr_nodiscard bool operator !=(half x) const { return (float)*this != (float)x; } - lol_attr_nodiscard bool operator <(half x) const { return (float)*this < (float)x; } - lol_attr_nodiscard bool operator >(half x) const { return (float)*this > (float)x; } - lol_attr_nodiscard bool operator <=(half x) const { return (float)*this <= (float)x; } - lol_attr_nodiscard bool operator >=(half x) const { return (float)*this >= (float)x; } + [[nodiscard]] bool operator ==(half x) const { return (float)*this == (float)x; } + [[nodiscard]] bool operator !=(half x) const { return (float)*this != (float)x; } + [[nodiscard]] bool operator <(half x) const { return (float)*this < (float)x; } + [[nodiscard]] bool operator >(half x) const { return (float)*this > (float)x; } + [[nodiscard]] bool operator <=(half x) const { return (float)*this <= (float)x; } + [[nodiscard]] bool operator >=(half x) const { return (float)*this >= (float)x; } - lol_attr_nodiscard bool operator !() const { return !(bits & 0x7fffu); } - lol_attr_nodiscard operator bool() const { return !!*this; } + [[nodiscard]] bool operator !() const { return !(bits & 0x7fffu); } + [[nodiscard]] operator bool() const { return !!*this; } inline half operator -() const { return makebits(bits ^ 0x8000u); } inline half operator +() const { return *this; } @@ -104,10 +104,10 @@ public: inline half &operator *=(half h) { return (*this = (half)(*this * h)); } inline half &operator /=(half h) { return (*this = (half)(*this / h)); } - lol_attr_nodiscard inline float operator +(half h) const { return (float)*this + (float)h; } - lol_attr_nodiscard inline float operator -(half h) const { return (float)*this - (float)h; } - lol_attr_nodiscard inline float operator *(half h) const { return (float)*this * (float)h; } - lol_attr_nodiscard inline float operator /(half h) const { return (float)*this / (float)h; } + [[nodiscard]] inline float operator +(half h) const { return (float)*this + (float)h; } + [[nodiscard]] inline float operator -(half h) const { return (float)*this - (float)h; } + [[nodiscard]] inline float operator *(half h) const { return (float)*this * (float)h; } + [[nodiscard]] inline float operator /(half h) const { return (float)*this / (float)h; } /* Factories */ static half makefast(float f);