This commit is contained in:
2026-02-14 14:30:25 +01:00
parent d3c0cb1066
commit ee5c156e56
48 changed files with 549 additions and 510 deletions
+38 -20
View File
@@ -25,17 +25,24 @@ THE SOFTWARE.
#pragma once
#define ITERABLE_ENUM_BEGIN(name) enum class name : int {
#define ITERABLE_ENUM_END ,end, begin = 0 }
#define ITERABLE_ENUM_BEGIN(name) \
enum class name : int \
{
#define ITERABLE_ENUM_END \
, end, begin = 0 \
}
template <class T>
class Iterable
template <class T> class Iterable
{
public:
Iterable(T value = T::begin) : mValue(value) {}
Iterable(const Iterable& other) : mValue(other.mValue) {}
public:
Iterable(T value = T::begin) : mValue(value)
{
}
Iterable(const Iterable &other) : mValue(other.mValue)
{
}
Iterable& operator++()
Iterable &operator++()
{
assert(mValue >= T::begin && mValue < T::end);
mValue = static_cast<T>(static_cast<int>(mValue) + 1);
@@ -49,7 +56,7 @@ public:
return prev;
}
Iterable& operator--()
Iterable &operator--()
{
assert(mValue >= T::end && mValue < T::begin);
mValue = static_cast<T>(static_cast<int>(mValue) - 1);
@@ -83,38 +90,49 @@ public:
return static_cast<T>(static_cast<int>(mValue) - static_cast<int>(i));
}
bool operator >(const T& other) const
bool operator>(const T &other) const
{
return static_cast<int>(mValue) > static_cast<int>(other);
}
bool operator >=(const T& other) const
bool operator>=(const T &other) const
{
return static_cast<int>(mValue) >= static_cast<int>(other);
}
bool operator <(const T& other) const
bool operator<(const T &other) const
{
return static_cast<int>(mValue) < static_cast<int>(other);
}
bool operator <=(const T& other) const
bool operator<=(const T &other) const
{
return static_cast<int>(mValue) <= static_cast<int>(other);
}
bool operator ==(const T& other) const
bool operator==(const T &other) const
{
return static_cast<int>(mValue) == static_cast<int>(other);
}
bool valid() const { return mValue != T::end; }
bool valid() const
{
return mValue != T::end;
}
operator T() const { return mValue; }
operator T&() { return mValue; }
T val() const { return mValue; }
operator T() const
{
return mValue;
}
operator T &()
{
return mValue;
}
T val() const
{
return mValue;
}
private:
private:
T mValue;
};