Merge pull request 'Using lots of macros to define operators for both int24 and int types' (#159) from int24_refactor into master
Reviewed-on: https://git.madvoxel.net/OpenVulkano/OpenVulkano/pulls/159 Reviewed-by: Georg Hagen <georg.hagen@madvoxel.com>
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
namespace OpenVulkano
|
namespace OpenVulkano
|
||||||
{
|
{
|
||||||
@@ -57,94 +58,17 @@ namespace OpenVulkano
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
int24 operator +(const int24& val) const
|
#define INT24_OPERATORS(op) \
|
||||||
{
|
template<typename T, std::enable_if_t<std::is_convertible_v<T, int>, bool> = true> \
|
||||||
return int24( (int)*this + (int)val );
|
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 operator -(const int24& val) const
|
INT24_OPERATORS(+)
|
||||||
{
|
INT24_OPERATORS(-)
|
||||||
return int24( (int)*this - (int)val );
|
INT24_OPERATORS(*)
|
||||||
}
|
INT24_OPERATORS(/)
|
||||||
|
#undef INT24_OPERATORS
|
||||||
int24 operator *(const int24& val) const
|
|
||||||
{
|
|
||||||
return int24( (int)*this * (int)val );
|
|
||||||
}
|
|
||||||
|
|
||||||
int24 operator /(const int24& val) const
|
|
||||||
{
|
|
||||||
return int24( (int)*this / (int)val );
|
|
||||||
}
|
|
||||||
|
|
||||||
int24 operator +(const int val) const
|
|
||||||
{
|
|
||||||
return int24( (int)*this + val );
|
|
||||||
}
|
|
||||||
|
|
||||||
int24 operator -(const int val) const
|
|
||||||
{
|
|
||||||
return int24( (int)*this - val );
|
|
||||||
}
|
|
||||||
|
|
||||||
int24 operator *(const int val) const
|
|
||||||
{
|
|
||||||
return int24( (int)*this * val );
|
|
||||||
}
|
|
||||||
|
|
||||||
int24 operator /(const int val) const
|
|
||||||
{
|
|
||||||
return int24( (int)*this / val );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int24& operator +=(const int24& val )
|
|
||||||
{
|
|
||||||
*this = *this + val;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
int24& operator -=(const int24& val )
|
|
||||||
{
|
|
||||||
*this = *this - val;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
int24& operator *=(const int24& val )
|
|
||||||
{
|
|
||||||
*this = *this * val;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
int24& operator /=(const int24& val )
|
|
||||||
{
|
|
||||||
*this = *this / val;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
int24& operator +=(const int val )
|
|
||||||
{
|
|
||||||
*this = *this + val;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
int24& operator -=(const int val )
|
|
||||||
{
|
|
||||||
*this = *this - val;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
int24& operator *=(const int val )
|
|
||||||
{
|
|
||||||
*this = *this * val;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
int24& operator /=(const int val )
|
|
||||||
{
|
|
||||||
*this = *this / val;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
int24 operator >>(const int val) const
|
int24 operator >>(const int val) const
|
||||||
{
|
{
|
||||||
@@ -183,64 +107,16 @@ namespace OpenVulkano
|
|||||||
return int24( -(int)*this );
|
return int24( -(int)*this );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator ==(const int24& val) const
|
template<typename T, std::enable_if_t<std::is_convertible_v<T, int>, bool> = true>
|
||||||
|
[[nodiscard]] bool operator==(const T& val) const
|
||||||
{
|
{
|
||||||
return (int)*this == (int)val;
|
return static_cast<int>(*this) == static_cast<int>(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator !=(const int24& val) const
|
template<typename T, std::enable_if_t<std::is_convertible_v<T, int>, bool> = true>
|
||||||
|
[[nodiscard]] constexpr auto operator<=>(const T& other) const
|
||||||
{
|
{
|
||||||
return (int)*this != (int)val;
|
return operator int() <=> static_cast<int>(other);
|
||||||
}
|
|
||||||
|
|
||||||
bool operator >=(const int24& val) const
|
|
||||||
{
|
|
||||||
return (int)*this >= (int)val;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator <=(const int24& val) const
|
|
||||||
{
|
|
||||||
return (int)*this <= (int)val;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator >(const int24& val) const
|
|
||||||
{
|
|
||||||
return (int)*this > (int)val;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator <(const int24& val) const
|
|
||||||
{
|
|
||||||
return (int)*this < (int)val;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator ==(const int val) const
|
|
||||||
{
|
|
||||||
return (int)*this == val;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator !=(const int val) const
|
|
||||||
{
|
|
||||||
return (int)*this != val;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator >=(const int val) const
|
|
||||||
{
|
|
||||||
return (int)*this >= val;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator <=(const int val) const
|
|
||||||
{
|
|
||||||
return (int)*this <= val;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator >(const int val) const
|
|
||||||
{
|
|
||||||
return ((int)*this) > val;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator <(const int val) const
|
|
||||||
{
|
|
||||||
return (int)*this < val;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user