| @@ -1,7 +1,7 @@ | |||||
| // | // | ||||
| // Lol Engine | // Lol Engine | ||||
| // | // | ||||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||||
| // Copyright © 2010–2023 Sam Hocevar <sam@hocevar.net> | |||||
| // | // | ||||
| // Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
| // the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
| @@ -20,6 +20,7 @@ | |||||
| #include "ops.h" | #include "ops.h" | ||||
| #include <lol/vector> // lol::vec_t | #include <lol/vector> // lol::vec_t | ||||
| #include <ostream> // std::ostream | #include <ostream> // std::ostream | ||||
| #include <tuple> // std::tuple | |||||
| #include <cmath> // std::fabs | #include <cmath> // std::fabs | ||||
| namespace lol | namespace lol | ||||
| @@ -1,7 +1,7 @@ | |||||
| // | // | ||||
| // Lol Engine | // Lol Engine | ||||
| // | // | ||||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||||
| // Copyright © 2010–2023 Sam Hocevar <sam@hocevar.net> | |||||
| // | // | ||||
| // Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
| // the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
| @@ -27,6 +27,7 @@ | |||||
| #include <tuple> // std::tuple | #include <tuple> // std::tuple | ||||
| #include <cassert> // assert() | #include <cassert> // assert() | ||||
| #include <cmath> // sqrt(), cbrt(), acos() | #include <cmath> // sqrt(), cbrt(), acos() | ||||
| #include <cstddef> // std::size_t | |||||
| namespace lol | namespace lol | ||||
| { | { | ||||
| @@ -265,13 +266,13 @@ struct [[nodiscard]] polynomial | |||||
| return {}; | return {}; | ||||
| } | } | ||||
| /* Access individual coefficients. This is read-only and returns a | |||||
| * 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). */ | |||||
| [[nodiscard]] inline T operator[](ptrdiff_t n) const | |||||
| // Access individual coefficients. This is read-only and returns a | |||||
| // 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). | |||||
| [[nodiscard]] inline T operator[](std::size_t n) const | |||||
| { | { | ||||
| if (n < 0 || n > degree()) | |||||
| if (degree() < 0 || n > std::size_t(degree())) | |||||
| return T(0); | return T(0); | ||||
| return m_coefficients[n]; | return m_coefficients[n]; | ||||
| @@ -1,7 +1,7 @@ | |||||
| // | // | ||||
| // Lol Engine | // Lol Engine | ||||
| // | // | ||||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||||
| // Copyright © 2010–2023 Sam Hocevar <sam@hocevar.net> | |||||
| // | // | ||||
| // Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
| // the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
| @@ -103,8 +103,9 @@ private: | |||||
| */ | */ | ||||
| #define LOL_COMMON_MEMBER_OPS(first) \ | #define LOL_COMMON_MEMBER_OPS(first) \ | ||||
| inline T& operator[](size_t n) { return (&this->first)[n]; } \ | |||||
| inline T const& operator[](size_t n) const { return (&this->first)[n]; } \ | |||||
| /* Use reinterpret_cast because static_cast is illegal here */ \ | |||||
| inline T& operator[](size_t n) { return reinterpret_cast<T*>(this)[n]; } \ | |||||
| inline T const& operator[](size_t n) const { return reinterpret_cast<T const*>(this)[n]; } \ | |||||
| \ | \ | ||||
| /* An explicit assignment operator is now mandatory */ \ | /* An explicit assignment operator is now mandatory */ \ | ||||
| inline type & operator =(type const &that) \ | inline type & operator =(type const &that) \ | ||||