Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Src/Base/AMReX_Enum.H
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ namespace amrex
{
return std::string(ET::class_name);
}

/** Return the underlying (u)int of an enum value
*
* Useful when building bitmasks.
*/
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);
}
Comment on lines +136 to +141
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.

}

#define AMREX_ENUM(CLASS, ...) \
Expand Down
Loading