Defining almost all operators in one go, added templates to the ops, separate == and <=> operator
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cinttypes>
|
||||
#include <type_traits>
|
||||
|
||||
namespace OpenVulkano
|
||||
{
|
||||
@@ -58,18 +59,10 @@ namespace OpenVulkano
|
||||
}
|
||||
|
||||
#define INT24_OPERATORS(op) \
|
||||
int24 operator op(const int24& val) const { return int24( (int)*this op (int)val ); } \
|
||||
int24 operator op(const int val) const { return int24( (int)*this op val ); }
|
||||
|
||||
INT24_OPERATORS(+)
|
||||
INT24_OPERATORS(-)
|
||||
INT24_OPERATORS(*)
|
||||
INT24_OPERATORS(/)
|
||||
#undef INT24_OPERATORS
|
||||
|
||||
#define INT24_OPERATORS(op) \
|
||||
int24& operator op##=(const int24& val ) { *this = *this op val; return *this; } \
|
||||
int24& operator op##=(const int val ) { *this = *this op val; return *this; }
|
||||
template<typename T, std::enable_if_t<std::is_convertible_v<T, int>, bool> = true> \
|
||||
int24 operator op(const T& val) const { return int24( (int)*this op static_cast<int>(val) ); } \
|
||||
template<typename T, std::enable_if_t<std::is_convertible_v<T, int>, bool> = true> \
|
||||
int24& operator op##=(const T& val ) { *this = *this op static_cast<int>(val); return *this; }
|
||||
|
||||
INT24_OPERATORS(+)
|
||||
INT24_OPERATORS(-)
|
||||
@@ -114,16 +107,16 @@ namespace OpenVulkano
|
||||
return int24( -(int)*this );
|
||||
}
|
||||
|
||||
#define INT24_OPERATORS(op) \
|
||||
bool operator op(const int24& val) const { return (int)*this op (int)val; } \
|
||||
bool operator op(const int val) const { return (int)*this op val; }
|
||||
template<typename T, std::enable_if_t<std::is_convertible_v<T, int>, bool> = true>
|
||||
[[nodiscard]] bool operator==(const T& val) const
|
||||
{
|
||||
return static_cast<int>(*this) == static_cast<int>(val);
|
||||
}
|
||||
|
||||
INT24_OPERATORS(==)
|
||||
INT24_OPERATORS(!=)
|
||||
INT24_OPERATORS(>=)
|
||||
INT24_OPERATORS(<=)
|
||||
INT24_OPERATORS(>)
|
||||
INT24_OPERATORS(<)
|
||||
#undef INT24_OPERATORS
|
||||
template<typename T, std::enable_if_t<std::is_convertible_v<T, int>, bool> = true>
|
||||
[[nodiscard]] constexpr auto operator<=>(const T& other) const
|
||||
{
|
||||
return operator int() <=> static_cast<int>(other);
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user