Changeset 1209


Ignore:
Timestamp:
Apr 10, 2012, 3:12:59 AM (11 years ago)
Author:
sam
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lol/math/vector.h

    r1177 r1209  
    7272    inline Vec2<T> operator =(Vec2<T> const &that);
    7373
    74     inline T& operator[](int n)
     74    inline T& operator[](size_t n)
    7575    {
    7676        int i = (N >> (4 * (1 - n))) & 3;
    7777        return static_cast<T*>(static_cast<void*>(this))[i];
    7878    }
    79     inline T const& operator[](int n) const
     79    inline T const& operator[](size_t n) const
    8080    {
    8181        int i = (N >> (4 * (1 - n))) & 3;
     
    8888    inline Vec3<T> operator =(Vec3<T> const &that);
    8989
    90     inline T& operator[](int n)
     90    inline T& operator[](size_t n)
    9191    {
    9292        int i = (N >> (4 * (2 - n))) & 3;
    9393        return static_cast<T*>(static_cast<void*>(this))[i];
    9494    }
    95     inline T const& operator[](int n) const
     95    inline T const& operator[](size_t n) const
    9696    {
    9797        int i = (N >> (4 * (2 - n))) & 3;
     
    104104    inline Vec4<T> operator =(Vec4<T> const &that);
    105105
    106     inline T& operator[](int n)
     106    inline T& operator[](size_t n)
    107107    {
    108108        int i = (N >> (4 * (3 - n))) & 3;
    109109        return static_cast<T*>(static_cast<void*>(this))[i];
    110110    }
    111     inline T const& operator[](int n) const
     111    inline T const& operator[](size_t n) const
    112112    {
    113113        int i = (N >> (4 * (3 - n))) & 3;
     
    121121
    122122#define DECLARE_MEMBER_OPS(tname) \
    123     inline T& operator[](int n) { return *(&this->x + n); } \
    124     inline T const& operator[](int n) const { return *(&this->x + n); } \
     123    inline T& operator[](size_t n) { return *(&this->x + n); } \
     124    inline T const& operator[](size_t n) const { return *(&this->x + n); } \
    125125    \
    126126    /* Visual Studio insists on having an assignment operator. */ \
     
    13511351        v3((T)0, (T)0, (T)0, val) {}
    13521352
    1353     inline Vec4<T>& operator[](int n) { return (&v0)[n]; }
    1354     inline Vec4<T> const& operator[](int n) const { return (&v0)[n]; }
     1353    inline Vec4<T>& operator[](size_t n) { return (&v0)[n]; }
     1354    inline Vec4<T> const& operator[](size_t n) const { return (&v0)[n]; }
    13551355
    13561356    T det() const;
Note: See TracChangeset for help on using the changeset viewer.