Skip to content

Commit 02f70bd

Browse files
ax3lWeiqunZhang
andauthored
AMReX Enum: Underlying Value (#4616)
## 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 --------- Co-authored-by: Weiqun Zhang <[email protected]>
1 parent 55ce8b3 commit 02f70bd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Src/Base/AMReX_Enum.H

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,17 @@ namespace detail
140140
{
141141
return std::string(ET::class_name);
142142
}
143+
144+
/** Return the underlying (u)int of an enum value
145+
*
146+
* Useful when building bitmasks.
147+
*/
148+
template <typename T, typename ET = amrex_enum_traits<T>,
149+
std::enable_if_t<ET::value,int> = 0>
150+
constexpr auto toUnderlying (T v) noexcept
151+
{
152+
return static_cast<std::underlying_type_t<T>>(v);
153+
}
143154
}
144155

145156
#define AMREX_ENUM(CLASS, ...) \

0 commit comments

Comments
 (0)