Enums backed by integers: feedback request

Enumerators should be mapped to ordered integer values and the types should convert out of the box.

Enum values could then be ordered specially and used with integer comparisons.

This would be useful for comparing the values of:

an enum to an integer: e.g. an enum defining rarity, and you want to know, if rarity > uncommon

2 enum instances, or comparing 2 enum types for their values:

1 enum instance holds progress level : completed, and one holds progress level: halted.

ProgressLevel : enum =

 NotStarted
 Started
 Halted
 Continued
 Completed

Then we could compare the values of two different instances, e.g.

if(Player1.ProgressLevel < Player2.ProgressLevel):

Or the values of the enumerators to eachother, e.g.

if(ProgressLevel > Started):

etc. These could be compared for proper ordinance

We could also easily select a random enumerator, and do numbers if other useful things like assign enumerators from integers, etc.

Right now devs are having to write their own conversion functions and enums just aren’t as useful as they could be without being properly enumerated.

So an array enum or for each map enum as a default function, setting int, etc, to be used with it?

https://dev.epicgames.com/documentation/en-us/fortnite/map-in-verse

Yes we can use maps, but enumerations should be enumerated - hence the name. Maps are overkill and the practice should be irrelevant. Not to mention, two elements of a enum→int map can have the same integer value, which could potentially cause issues. Not the case with typical enums.

It seems to me that you just want the greater than and less than comparison operators to work with enums such that an enum value lower in the list is considered greater than an enum value higher in the list.

The integer part of the proposal is an implementation detail that is not important to you, right?

1 Like

The integer conversion is actually necessary as well. If the types convert, we can assign enums from integer values and vice versa. For instance, choosing a random enumerator with a random integer would be possible.

1 Like