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
8257466: Improve enum iteration #1530
Conversation
👋 Welcome back kbarrett! A progress list of the required criteria for merging this PR into |
@kimbarrett |
Webrevs
|
template<> struct EnumeratorRange<T> { \ | ||
static constexpr EnumeratorRangeImpl::Underlying<T> _start = \ | ||
EnumeratorRangeImpl::underlying<T>(Start); \ | ||
static constexpr EnumeratorRangeImpl::Underlying<T> _end = \ |
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.
Why do we need to call underlying<T>(Start)
here? Can it be simplified as
static constexpr EnumeratorRangeImpl::Underlying<T> _start = Start;
or
static constexpr EnumeratorRangeImpl::Underlying<T> _start {Start};
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.
I'd earlier considered requiring the type of Start and End be Underlying rather than convertible to that. The underlying() function is a partial remnant of that. I'll remove it.
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.
Using brace initialization is the way to go, as it prevents narrowing.
@kimbarrett This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been no new commits pushed to the ➡️ To integrate this PR with the above commit message to the |
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.
Changes looks good Kim.
Lois
/summary Improve support for enums that are just range of values, without named enumerators. |
@kimbarrett Setting summary to |
/summary Improve support for iteration on enums that are just range of values, without named enumerators. |
@kimbarrett Updating existing summary to |
/integrate |
@kimbarrett Pushed as commit 3932527. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Please review this collection of improvements to the recently added enum
iteration facility. These improvements are based on usage in some
in-development changes.
(1) Added EnumType nested type to EnumRange and EnumIterator. It is an alias
for the enum type that is a template parameter for those classes. This is
useful when dealing with a range or iterator whose associated enum type is
not known because the range/iterator is a template parameter.
(2) Added EnumRange::index(T), which converts the argument enumerator to
a zero-based index into the range of values. This is useful when mapping
from an enumerator to a corresponding array index, for example.
(3) Allow enum range bounds to be specified using start and (exclusive) end
integral (underlying type) values. This is useful when dealing with enums
that are just value ranges and don't have named enumerators. As part of
this, changes the enum iteration traits mechanism to use start/end rather
than first/last, as that seems to be a little easier to deal with.
(4) Added accessors for the first and last enumerator values of a range.
(5) Added gtest for enum iteration.
Testing: tier1
/label hotspot
Progress
Issue
Reviewers
Download
$ git fetch https://git.openjdk.java.net/jdk pull/1530/head:pull/1530
$ git checkout pull/1530