Skip to content

Commit 01ec100

Browse files
committed
Add subscript operators for the XMINT2~4 and XMFLOAT2~4 types
1 parent a8ddf53 commit 01ec100

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

Inc/DirectXMath.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,8 @@ namespace DirectX
604604
constexpr XMFLOAT2(float _x, float _y) noexcept : x(_x), y(_y) {}
605605
explicit XMFLOAT2(_In_reads_(2) const float* pArray) noexcept : x(pArray[0]), y(pArray[1]) {}
606606

607+
float& operator [] (_In_range_(0, 1) int32_t index) noexcept { return reinterpret_cast<float*>(this)[index]; }
608+
const float operator [] (_In_range_(0, 1) int32_t index) const noexcept { return reinterpret_cast<const float*>(this)[index]; }
607609
#if (__cplusplus >= 202002L)
608610
bool operator == (const XMFLOAT2&) const = default;
609611
auto operator <=> (const XMFLOAT2&) const = default;
@@ -634,6 +636,8 @@ namespace DirectX
634636
constexpr XMINT2(int32_t _x, int32_t _y) noexcept : x(_x), y(_y) {}
635637
explicit XMINT2(_In_reads_(2) const int32_t* pArray) noexcept : x(pArray[0]), y(pArray[1]) {}
636638

639+
int32_t& operator [] (_In_range_(0, 1) int32_t index) noexcept { return reinterpret_cast<int32_t*>(this)[index]; }
640+
const int32_t operator [] (_In_range_(0, 1) int32_t index) const noexcept { return reinterpret_cast<const int32_t*>(this)[index]; }
637641
#if (__cplusplus >= 202002L)
638642
bool operator == (const XMINT2&) const = default;
639643
auto operator <=> (const XMINT2&) const = default;
@@ -657,6 +661,8 @@ namespace DirectX
657661
constexpr XMUINT2(uint32_t _x, uint32_t _y) noexcept : x(_x), y(_y) {}
658662
explicit XMUINT2(_In_reads_(2) const uint32_t* pArray) noexcept : x(pArray[0]), y(pArray[1]) {}
659663

664+
uint32_t& operator [] (_In_range_(0, 1) int32_t index) noexcept { return reinterpret_cast<uint32_t*>(this)[index]; }
665+
const uint32_t operator [] (_In_range_(0, 1) int32_t index) const noexcept { return reinterpret_cast<const uint32_t*>(this)[index]; }
660666
#if (__cplusplus >= 202002L)
661667
bool operator == (const XMUINT2&) const = default;
662668
auto operator <=> (const XMUINT2&) const = default;
@@ -681,6 +687,9 @@ namespace DirectX
681687

682688
constexpr XMFLOAT3(float _x, float _y, float _z) noexcept : x(_x), y(_y), z(_z) {}
683689
explicit XMFLOAT3(_In_reads_(3) const float* pArray) noexcept : x(pArray[0]), y(pArray[1]), z(pArray[2]) {}
690+
691+
float& operator [] (_In_range_(0, 2) int32_t index) noexcept { return reinterpret_cast<float*>(this)[index]; }
692+
const float operator [] (_In_range_(0, 2) int32_t index) const noexcept { return reinterpret_cast<const float*>(this)[index]; }
684693
};
685694

686695
// 3D Vector; 32 bit floating point components aligned on a 16 byte boundary
@@ -708,6 +717,8 @@ namespace DirectX
708717
constexpr XMINT3(int32_t _x, int32_t _y, int32_t _z) noexcept : x(_x), y(_y), z(_z) {}
709718
explicit XMINT3(_In_reads_(3) const int32_t* pArray) noexcept : x(pArray[0]), y(pArray[1]), z(pArray[2]) {}
710719

720+
int32_t& operator [] (_In_range_(0, 2) int32_t index) noexcept { return reinterpret_cast<int32_t*>(this)[index]; }
721+
const int32_t operator [] (_In_range_(0, 2) int32_t index) const noexcept { return reinterpret_cast<const int32_t*>(this)[index]; }
711722
#if (__cplusplus >= 202002L)
712723
bool operator == (const XMINT3&) const = default;
713724
auto operator <=> (const XMINT3&) const = default;
@@ -732,6 +743,8 @@ namespace DirectX
732743
constexpr XMUINT3(uint32_t _x, uint32_t _y, uint32_t _z) noexcept : x(_x), y(_y), z(_z) {}
733744
explicit XMUINT3(_In_reads_(3) const uint32_t* pArray) noexcept : x(pArray[0]), y(pArray[1]), z(pArray[2]) {}
734745

746+
uint32_t& operator [] (_In_range_(0, 2) int32_t index) noexcept { return reinterpret_cast<uint32_t*>(this)[index]; }
747+
const uint32_t operator [] (_In_range_(0, 2) int32_t index) const noexcept { return reinterpret_cast<const uint32_t*>(this)[index]; }
735748
#if (__cplusplus >= 202002L)
736749
bool operator == (const XMUINT3&) const = default;
737750
auto operator <=> (const XMUINT3&) const = default;
@@ -758,6 +771,8 @@ namespace DirectX
758771
constexpr XMFLOAT4(float _x, float _y, float _z, float _w) noexcept : x(_x), y(_y), z(_z), w(_w) {}
759772
explicit XMFLOAT4(_In_reads_(4) const float* pArray) noexcept : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {}
760773

774+
float& operator [] (_In_range_(0, 3) int32_t index) noexcept { return reinterpret_cast<float*>(this)[index]; }
775+
const float operator [] (_In_range_(0, 3) int32_t index) const noexcept { return reinterpret_cast<const float*>(this)[index]; }
761776
#if (__cplusplus >= 202002L)
762777
bool operator == (const XMFLOAT4&) const = default;
763778
auto operator <=> (const XMFLOAT4&) const = default;
@@ -790,6 +805,8 @@ namespace DirectX
790805
constexpr XMINT4(int32_t _x, int32_t _y, int32_t _z, int32_t _w) noexcept : x(_x), y(_y), z(_z), w(_w) {}
791806
explicit XMINT4(_In_reads_(4) const int32_t* pArray) noexcept : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {}
792807

808+
int32_t& operator [] (_In_range_(0, 3) int32_t index) noexcept { return reinterpret_cast<int32_t*>(this)[index]; }
809+
const int32_t operator [] (_In_range_(0, 3) int32_t index) const noexcept { return reinterpret_cast<const int32_t*>(this)[index]; }
793810
#if (__cplusplus >= 202002L)
794811
bool operator == (const XMINT4&) const = default;
795812
auto operator <=> (const XMINT4&) const = default;
@@ -815,6 +832,8 @@ namespace DirectX
815832
constexpr XMUINT4(uint32_t _x, uint32_t _y, uint32_t _z, uint32_t _w) noexcept : x(_x), y(_y), z(_z), w(_w) {}
816833
explicit XMUINT4(_In_reads_(4) const uint32_t* pArray) noexcept : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {}
817834

835+
uint32_t& operator [] (_In_range_(0, 3) int32_t index) noexcept { return reinterpret_cast<uint32_t*>(this)[index]; }
836+
const uint32_t operator [] (_In_range_(0, 3) int32_t index) const noexcept { return reinterpret_cast<const uint32_t*>(this)[index]; }
818837
#if (__cplusplus >= 202002L)
819838
bool operator == (const XMUINT4&) const = default;
820839
auto operator <=> (const XMUINT4&) const = default;

0 commit comments

Comments
 (0)