Support to get highest and lowest values from enums.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-03-12 19:28:26 +01:00
parent 784af6d51a
commit 5710329f39
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
1 changed files with 20 additions and 1 deletions

View File

@ -26,6 +26,16 @@
out = name::x; \
return true;
#
#define ENUM_GET_HIGHEST(x, name) \
if ((int64_t)name::x > highest) { \
highest = (int64_t)name::x; \
}
#
#define ENUM_GET_LOWEST(x, name) \
if ((int64_t)name::x < lowest) { \
lowest = (int64_t)name::x; \
}
#
#define ARRAY_NAME(x, name) name::x,
/*!
@ -68,6 +78,16 @@
static std::vector<name> GetValues() { return {MACRO_UTILS_FOR_EACH(ARRAY_NAME, name, values)}; } \
constexpr static name Last() { return name::MACRO_UTILS_GET_LAST(values); } \
constexpr static name First() { return name::MACRO_UTILS_GET_FIRST(values); } \
constexpr static name Highest() { \
int64_t highest = -9223372036854775807; \
MACRO_UTILS_FOR_EACH(ENUM_GET_HIGHEST, name, values) \
return (name)highest; \
} \
constexpr static name Lowest() { \
int64_t lowest = 9223372036854775807; \
MACRO_UTILS_FOR_EACH(ENUM_GET_LOWEST, name, values) \
return (name)lowest; \
} \
\
private: \
constexpr static name ParseCaseInsensitive(const char* input) { \
@ -79,4 +99,3 @@
return false; \
} \
};