Implement spaceship operator for geom::vector
This commit is contained in:
parent
e62fc51052
commit
eb1e367085
1 changed files with 14 additions and 0 deletions
|
|
@ -9,6 +9,7 @@
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <compare>
|
||||||
|
|
||||||
namespace psemek::geom
|
namespace psemek::geom
|
||||||
{
|
{
|
||||||
|
|
@ -97,6 +98,19 @@ namespace psemek::geom
|
||||||
return !(v1 < v2);
|
return !(v1 < v2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T, std::size_t N>
|
||||||
|
std::strong_ordering operator <=> (vector<T, N> const & v1, vector<T, N> const & v2)
|
||||||
|
{
|
||||||
|
for (std::size_t i = 0; i < N; ++i)
|
||||||
|
{
|
||||||
|
if (v1[i] < v2[i])
|
||||||
|
return std::strong_ordering::less;
|
||||||
|
if (v1[i] > v2[i])
|
||||||
|
return std::strong_ordering::greater;
|
||||||
|
}
|
||||||
|
return std::strong_ordering::equal;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T1, typename T, std::size_t N>
|
template <typename T1, typename T, std::size_t N>
|
||||||
vector<T1, N> cast(vector<T, N> const & v)
|
vector<T1, N> cast(vector<T, N> const & v)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue