-
Notifications
You must be signed in to change notification settings - Fork 484
Countable Enums #349
base: master
Are you sure you want to change the base?
Countable Enums #349
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,5 +52,11 @@ struct hash<::testsuite::access_flags> { | |
| return std::hash<unsigned>()(static_cast<unsigned>(type)); | ||
| } | ||
| }; | ||
| template <> | ||
| class numeric_limits<::testsuite::access_flags> : public numeric_limits<unsigned> { | ||
| public: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs to be outdented |
||
| static constexpr bool is_specialized = true; | ||
| static constexpr ::testsuite::access_flags max() noexcept { return static_cast<::testsuite::access_flags>(9); } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this calculation is correct for flags. A flag type like this may have 9 values, but its range is a full 9 bits. |
||
| }; | ||
|
|
||
| } // namespace std | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,9 @@ enum class color : int { | |
| INDIGO, | ||
| VIOLET, | ||
| }; | ||
| constexpr color operator++(color const& r, int increment) noexcept { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you adding increment, but not decrement or any other arithmatic operations? Feels like a partial feature. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the increment operator is being used as a way to iterate over a set of enum values, it may be more C++ idiomatic to define an |
||
| return color((int)r + increment); | ||
| } | ||
|
|
||
| } // namespace testsuite | ||
|
|
||
|
|
@@ -32,5 +35,12 @@ struct hash<::testsuite::color> { | |
| return std::hash<int>()(static_cast<int>(type)); | ||
| } | ||
| }; | ||
| template <> | ||
| class numeric_limits<::testsuite::color> : public numeric_limits<int> { | ||
| public: | ||
| static constexpr bool is_specialized = true; | ||
| static constexpr ::testsuite::color min() noexcept { return ::testsuite::color::RED; } | ||
| static constexpr ::testsuite::color max() noexcept { return ::testsuite::color::VIOLET; } | ||
| }; | ||
|
|
||
| } // namespace std | ||
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.
See my comment in the example generated code. I wonder why it would make sense to define only one such operator, rather than a full set.
Increment in particular has the issue that it can cause overflow/underflow and result in illegal values.