Skip to content

Conversation

ax3l
Copy link
Member

@ax3l ax3l commented Aug 18, 2025

Summary

Sometimes one needs the underlying (u)int value of an enum class, e.g., when building bitmasks. This adds a helper function to AMREX_ENUM.

Additional background

BLAST-ImpactX/impactx#1104

Checklist

The proposed changes:

  • fix a bug or incorrect behavior in AMReX
  • add new capabilities to AMReX
  • changes answers in the test suite to more than roundoff level
  • are likely to significantly affect the results of downstream AMReX users
  • include documentation in the code and/or rst files, if appropriate

Sometimes one needs the underlying (u)int type of an enum,
e.g., when building bitmasks. This adds a helper function to
`AMREX_ENUM`.
@ax3l ax3l force-pushed the topic-enum-underlying branch from 929e83f to dbc02ed Compare August 18, 2025 19:51
@ax3l ax3l changed the title AMReX Enum: Underlying Type AMReX Enum: Underlying Value Aug 18, 2025
Comment on lines +136 to +141
template <typename T, typename ET = amrex_enum_traits<T>,
std::enable_if_t<ET::value,int> = 0>
constexpr auto getEnumUnderlyingValue (T v) noexcept
{
return static_cast<std::underlying_type_t<T>>(v);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can make T also an int, because we hard-code int in AMREX_ENUM for now. Let me know what you prefer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://en.cppreference.com/w/cpp/utility/to_underlying.html We could also use a name that is similar to the future C++ standard, like toUnderlying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants