mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 22:58:46 +00:00
Merge pull request #4477 from laytan/enum-value-has-name
reflect: add `enum_value_has_name` proc
This commit is contained in:
@@ -723,6 +723,27 @@ enum_name_from_value_any :: proc(value: any) -> (name: string, ok: bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Returns whether the value given has a defined name in the enum type.
|
||||||
|
*/
|
||||||
|
@(require_results)
|
||||||
|
enum_value_has_name :: proc(value: $T) -> bool where intrinsics.type_is_enum(T) {
|
||||||
|
when len(T) == cap(T) {
|
||||||
|
return value >= min(T) && value <= max(T)
|
||||||
|
} else {
|
||||||
|
if value < min(T) || value > max(T) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for valid_value in T {
|
||||||
|
if valid_value == value {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user