-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Add to_underlying_type to cast enum to underlying #1028
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks handy!
Summary: - It is verbose at the call sites to cast an enum or enum class to its underlying type. - Introduce `to_underlying_type`, which, given an enum or enum class, returns the value from static casting to the underlying type.
11138cf
to
1ab8ba0
Compare
Thanks for the review, @yfeldblum. I've fixed up your comments. What do you think about extending
This would let callers use this utility in more generic programming contexts where you know you are working a regular value type, but not sure whether it is wrapped in an enum or enum class. It eliminates the need to do SFINAE machinery (such as checking if the type is an enum) to not force a hard error in a caller using |
Maybe, but that sounds like a completely different function. E.g. Then you run into questions like, why not work on arithmetic but non-integral types, etc.?
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yfeldblum has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: - It is verbose at the call sites to cast an enum or enum class to its underlying type. - Introduce `to_underlying_type`, which, given an enum or enum class, returns the value from static casting to the underlying type. Pull Request resolved: facebook#1028 Reviewed By: stevegury Differential Revision: D14199619 Pulled By: yfeldblum fbshipit-source-id: fde85b9be50945a390b18ba1448a0137f3d7b63e
Summary:
underlying type.
to_underlying_type
, which, given an enum or enum class,returns the value from static casting to the underlying type.