From 5d2ddbdb6f818cfd8bf09b792fe0ba9d340c7aaf Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 10 Apr 2012 01:12:59 +0000 Subject: [PATCH] math: use size_t instead of int for vector subscript to avoid torrents of compiler warnings in 64-bit mode when sizeof(foo) is used as the argument for the array subscript operator. No need to care about the non-signedness since only positive indices work. --- src/lol/math/vector.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/lol/math/vector.h b/src/lol/math/vector.h index 39266a18..12bb4600 100644 --- a/src/lol/math/vector.h +++ b/src/lol/math/vector.h @@ -71,12 +71,12 @@ template struct XVec2 { inline Vec2 operator =(Vec2 const &that); - inline T& operator[](int n) + inline T& operator[](size_t n) { int i = (N >> (4 * (1 - n))) & 3; return static_cast(static_cast(this))[i]; } - inline T const& operator[](int n) const + inline T const& operator[](size_t n) const { int i = (N >> (4 * (1 - n))) & 3; return static_cast(static_cast(this))[i]; @@ -87,12 +87,12 @@ template struct XVec3 { inline Vec3 operator =(Vec3 const &that); - inline T& operator[](int n) + inline T& operator[](size_t n) { int i = (N >> (4 * (2 - n))) & 3; return static_cast(static_cast(this))[i]; } - inline T const& operator[](int n) const + inline T const& operator[](size_t n) const { int i = (N >> (4 * (2 - n))) & 3; return static_cast(static_cast(this))[i]; @@ -103,12 +103,12 @@ template struct XVec4 { inline Vec4 operator =(Vec4 const &that); - inline T& operator[](int n) + inline T& operator[](size_t n) { int i = (N >> (4 * (3 - n))) & 3; return static_cast(static_cast(this))[i]; } - inline T const& operator[](int n) const + inline T const& operator[](size_t n) const { int i = (N >> (4 * (3 - n))) & 3; return static_cast(static_cast(this))[i]; @@ -120,8 +120,8 @@ template struct XVec4 */ #define DECLARE_MEMBER_OPS(tname) \ - inline T& operator[](int n) { return *(&this->x + n); } \ - inline T const& operator[](int n) const { return *(&this->x + n); } \ + inline T& operator[](size_t n) { return *(&this->x + n); } \ + inline T const& operator[](size_t n) const { return *(&this->x + n); } \ \ /* Visual Studio insists on having an assignment operator. */ \ inline tname const & operator =(tname const &that) \ @@ -1350,8 +1350,8 @@ template struct Mat4 v2((T)0, (T)0, val, (T)0), v3((T)0, (T)0, (T)0, val) {} - inline Vec4& operator[](int n) { return (&v0)[n]; } - inline Vec4 const& operator[](int n) const { return (&v0)[n]; } + inline Vec4& operator[](size_t n) { return (&v0)[n]; } + inline Vec4 const& operator[](size_t n) const { return (&v0)[n]; } T det() const; Mat4 invert() const;