diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/string_util.cpp | 2 | ||||
-rw-r--r-- | src/common/string_util.h | 2 | ||||
-rw-r--r-- | src/common/vector_math.h | 24 |
3 files changed, 13 insertions, 15 deletions
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index bad311793..6959915fa 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp @@ -117,7 +117,7 @@ std::string StringFromFormat(const char* format, ...) { } // For Debugging. Read out an u8 array. -std::string ArrayToString(const u8* data, u32 size, int line_len, bool spaces) { +std::string ArrayToString(const u8* data, size_t size, int line_len, bool spaces) { std::ostringstream oss; oss << std::setfill('0') << std::hex; diff --git a/src/common/string_util.h b/src/common/string_util.h index 075bf4ecb..259360aec 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -33,7 +33,7 @@ inline void CharArrayFromFormat(char (&out)[Count], const char* format, ...) { } // Good -std::string ArrayToString(const u8* data, u32 size, int line_len = 20, bool spaces = true); +std::string ArrayToString(const u8* data, size_t size, int line_len = 20, bool spaces = true); std::string StripSpaces(const std::string& s); std::string StripQuotes(const std::string& s); diff --git a/src/common/vector_math.h b/src/common/vector_math.h index 6e2a5ad60..3f0057d9e 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h @@ -31,6 +31,7 @@ #pragma once #include <cmath> +#include <type_traits> namespace Math { @@ -90,7 +91,8 @@ public: y -= other.y; } - Vec2<decltype(-T{})> operator-() const { + template <typename U = T> + Vec2<std::enable_if_t<std::is_signed<U>::value, U>> operator-() const { return MakeVec(-x, -y); } Vec2<decltype(T{} * T{})> operator*(const Vec2& other) const { @@ -102,8 +104,7 @@ public: } template <typename V> void operator*=(const V& f) { - x *= f; - y *= f; + *this = *this * f; } template <typename V> Vec2<decltype(T{} / V{})> operator/(const V& f) const { @@ -247,7 +248,8 @@ public: z -= other.z; } - Vec3<decltype(-T{})> operator-() const { + template <typename U = T> + Vec3<std::enable_if_t<std::is_signed<U>::value, U>> operator-() const { return MakeVec(-x, -y, -z); } Vec3<decltype(T{} * T{})> operator*(const Vec3& other) const { @@ -259,9 +261,7 @@ public: } template <typename V> void operator*=(const V& f) { - x *= f; - y *= f; - z *= f; + *this = *this * f; } template <typename V> Vec3<decltype(T{} / V{})> operator/(const V& f) const { @@ -462,7 +462,8 @@ public: w -= other.w; } - Vec4<decltype(-T{})> operator-() const { + template <typename U = T> + Vec4<std::enable_if_t<std::is_signed<U>::value, U>> operator-() const { return MakeVec(-x, -y, -z, -w); } Vec4<decltype(T{} * T{})> operator*(const Vec4& other) const { @@ -474,10 +475,7 @@ public: } template <typename V> void operator*=(const V& f) { - x *= f; - y *= f; - z *= f; - w *= f; + *this = *this * f; } template <typename V> Vec4<decltype(T{} / V{})> operator/(const V& f) const { @@ -720,4 +718,4 @@ static inline Vec4<T> MakeVec(const T& x, const Vec3<T>& yzw) { return MakeVec(x, yzw[0], yzw[1], yzw[2]); } -} // namespace +} // namespace Math |