-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SUGGESTION] Creating an enum instance from a raw integer #1217
Comments
I like the idea... but maybe the syntax should be get_underlying and set_underlying ... possibly value as well, so we don't deviate so much from how people are used to using enums and enum classes, where currently you have to cast from/to std::underlying_type_t and you could look for underlying in both cpp1 and cpp2 at the same time to detect potential issues. I'm curious how others feel about this as well. |
In my opinion, to get the raw value we should just be able to cast, for example, by saying |
Being able to get the raw value with My sense is that |
It is always safe to get the underlying value, so the |
Not me, sorry. |
Apologies. |
In case I didn't miss anything, it is currently not possible to create an enum instance from a raw integer.
If the values of enum instances should matter at all (which is suggested by the possibility to assign custom values to specific enum members, and by the existence of
get_raw_value()
), then I believe it should also be possible to create an enum instance from an integer.A specific use case I have in mind:
Ways to make something like this possible could be:
operator= : (implicit out this, _val: i64)
public.Square::from_raw_value(val: i64)
) to make clear that converting an integer into an enum is an unusual/dangerous operationThe text was updated successfully, but these errors were encountered: