Skip to content

Commit 057ef1d

Browse files
authored
Add C++20 defaulted comparisions to structs to support all comparisons (#147)
1 parent bbba978 commit 057ef1d

File tree

1 file changed

+68
-4
lines changed

1 file changed

+68
-4
lines changed

Inc/DirectXMath.h

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@
171171
#define XM_ALIGNED_STRUCT(x) __declspec(align(x)) struct
172172
#endif
173173

174+
#if (__cplusplus >= 202002L)
175+
#include <compare>
176+
#endif
177+
174178
/****************************************************************************
175179
*
176180
* Conditional intrinsics
@@ -593,6 +597,11 @@ namespace DirectX
593597

594598
constexpr XMFLOAT2(float _x, float _y) noexcept : x(_x), y(_y) {}
595599
explicit XMFLOAT2(_In_reads_(2) const float* pArray) noexcept : x(pArray[0]), y(pArray[1]) {}
600+
601+
#if (__cplusplus >= 202002L)
602+
bool operator == (const XMFLOAT2&) const = default;
603+
auto operator <=> (const XMFLOAT2&) const = default;
604+
#endif
596605
};
597606

598607
// 2D Vector; 32 bit floating point components aligned on a 16 byte boundary
@@ -618,6 +627,11 @@ namespace DirectX
618627

619628
constexpr XMINT2(int32_t _x, int32_t _y) noexcept : x(_x), y(_y) {}
620629
explicit XMINT2(_In_reads_(2) const int32_t* pArray) noexcept : x(pArray[0]), y(pArray[1]) {}
630+
631+
#if (__cplusplus >= 202002L)
632+
bool operator == (const XMINT2&) const = default;
633+
auto operator <=> (const XMINT2&) const = default;
634+
#endif
621635
};
622636

623637
// 2D Vector; 32 bit unsigned integer components
@@ -636,6 +650,11 @@ namespace DirectX
636650

637651
constexpr XMUINT2(uint32_t _x, uint32_t _y) noexcept : x(_x), y(_y) {}
638652
explicit XMUINT2(_In_reads_(2) const uint32_t* pArray) noexcept : x(pArray[0]), y(pArray[1]) {}
653+
654+
#if (__cplusplus >= 202002L)
655+
bool operator == (const XMUINT2&) const = default;
656+
auto operator <=> (const XMUINT2&) const = default;
657+
#endif
639658
};
640659

641660
//------------------------------------------------------------------------------
@@ -682,6 +701,11 @@ namespace DirectX
682701

683702
constexpr XMINT3(int32_t _x, int32_t _y, int32_t _z) noexcept : x(_x), y(_y), z(_z) {}
684703
explicit XMINT3(_In_reads_(3) const int32_t* pArray) noexcept : x(pArray[0]), y(pArray[1]), z(pArray[2]) {}
704+
705+
#if (__cplusplus >= 202002L)
706+
bool operator == (const XMINT3&) const = default;
707+
auto operator <=> (const XMINT3&) const = default;
708+
#endif
685709
};
686710

687711
// 3D Vector; 32 bit unsigned integer components
@@ -701,6 +725,11 @@ namespace DirectX
701725

702726
constexpr XMUINT3(uint32_t _x, uint32_t _y, uint32_t _z) noexcept : x(_x), y(_y), z(_z) {}
703727
explicit XMUINT3(_In_reads_(3) const uint32_t* pArray) noexcept : x(pArray[0]), y(pArray[1]), z(pArray[2]) {}
728+
729+
#if (__cplusplus >= 202002L)
730+
bool operator == (const XMUINT3&) const = default;
731+
auto operator <=> (const XMUINT3&) const = default;
732+
#endif
704733
};
705734

706735
//------------------------------------------------------------------------------
@@ -722,6 +751,11 @@ namespace DirectX
722751

723752
constexpr XMFLOAT4(float _x, float _y, float _z, float _w) noexcept : x(_x), y(_y), z(_z), w(_w) {}
724753
explicit XMFLOAT4(_In_reads_(4) const float* pArray) noexcept : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {}
754+
755+
#if (__cplusplus >= 202002L)
756+
bool operator == (const XMFLOAT4&) const = default;
757+
auto operator <=> (const XMFLOAT4&) const = default;
758+
#endif
725759
};
726760

727761
// 4D Vector; 32 bit floating point components aligned on a 16 byte boundary
@@ -749,6 +783,11 @@ namespace DirectX
749783

750784
constexpr XMINT4(int32_t _x, int32_t _y, int32_t _z, int32_t _w) noexcept : x(_x), y(_y), z(_z), w(_w) {}
751785
explicit XMINT4(_In_reads_(4) const int32_t* pArray) noexcept : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {}
786+
787+
#if (__cplusplus >= 202002L)
788+
bool operator == (const XMINT4&) const = default;
789+
auto operator <=> (const XMINT4&) const = default;
790+
#endif
752791
};
753792

754793
// 4D Vector; 32 bit unsigned integer components
@@ -769,6 +808,11 @@ namespace DirectX
769808

770809
constexpr XMUINT4(uint32_t _x, uint32_t _y, uint32_t _z, uint32_t _w) noexcept : x(_x), y(_y), z(_z), w(_w) {}
771810
explicit XMUINT4(_In_reads_(4) const uint32_t* pArray) noexcept : x(pArray[0]), y(pArray[1]), z(pArray[2]), w(pArray[3]) {}
811+
812+
#if (__cplusplus >= 202002L)
813+
bool operator == (const XMUINT4&) const = default;
814+
auto operator <=> (const XMUINT4&) const = default;
815+
#endif
772816
};
773817

774818
#ifdef __clang__
@@ -808,8 +852,13 @@ namespace DirectX
808852
_31(m20), _32(m21), _33(m22) {}
809853
explicit XMFLOAT3X3(_In_reads_(9) const float* pArray) noexcept;
810854

811-
float operator() (size_t Row, size_t Column) const noexcept { return m[Row][Column]; }
855+
float operator() (size_t Row, size_t Column) const noexcept { return m[Row][Column]; }
812856
float& operator() (size_t Row, size_t Column) noexcept { return m[Row][Column]; }
857+
858+
#if (__cplusplus >= 202002L)
859+
bool operator == (const XMFLOAT3X3&) const = default;
860+
auto operator <=> (const XMFLOAT3X3&) const = default;
861+
#endif
813862
};
814863

815864
//------------------------------------------------------------------------------
@@ -847,8 +896,13 @@ namespace DirectX
847896
_41(m30), _42(m31), _43(m32) {}
848897
explicit XMFLOAT4X3(_In_reads_(12) const float* pArray) noexcept;
849898

850-
float operator() (size_t Row, size_t Column) const noexcept { return m[Row][Column]; }
899+
float operator() (size_t Row, size_t Column) const noexcept { return m[Row][Column]; }
851900
float& operator() (size_t Row, size_t Column) noexcept { return m[Row][Column]; }
901+
902+
#if (__cplusplus >= 202002L)
903+
bool operator == (const XMFLOAT4X3&) const = default;
904+
auto operator <=> (const XMFLOAT4X3&) const = default;
905+
#endif
852906
};
853907

854908
// 4x3 Row-major Matrix: 32 bit floating point components aligned on a 16 byte boundary
@@ -889,8 +943,13 @@ namespace DirectX
889943
_31(m20), _32(m21), _33(m22), _34(m23) {}
890944
explicit XMFLOAT3X4(_In_reads_(12) const float* pArray) noexcept;
891945

892-
float operator() (size_t Row, size_t Column) const noexcept { return m[Row][Column]; }
946+
float operator() (size_t Row, size_t Column) const noexcept { return m[Row][Column]; }
893947
float& operator() (size_t Row, size_t Column) noexcept { return m[Row][Column]; }
948+
949+
#if (__cplusplus >= 202002L)
950+
bool operator == (const XMFLOAT3X4&) const = default;
951+
auto operator <=> (const XMFLOAT3X4&) const = default;
952+
#endif
894953
};
895954

896955
// 3x4 Column-major Matrix: 32 bit floating point components aligned on a 16 byte boundary
@@ -933,8 +992,13 @@ namespace DirectX
933992
_41(m30), _42(m31), _43(m32), _44(m33) {}
934993
explicit XMFLOAT4X4(_In_reads_(16) const float* pArray) noexcept;
935994

936-
float operator() (size_t Row, size_t Column) const noexcept { return m[Row][Column]; }
995+
float operator() (size_t Row, size_t Column) const noexcept { return m[Row][Column]; }
937996
float& operator() (size_t Row, size_t Column) noexcept { return m[Row][Column]; }
997+
998+
#if (__cplusplus >= 202002L)
999+
bool operator == (const XMFLOAT4X4&) const = default;
1000+
auto operator <=> (const XMFLOAT4X4&) const = default;
1001+
#endif
9381002
};
9391003

9401004
// 4x4 Matrix: 32 bit floating point components aligned on a 16 byte boundary

0 commit comments

Comments
 (0)