Skip to content

Commit dbc02ed

Browse files
committed
AMReX Enum: Underlying Value
Sometimes one needs the underlying (u)int type of an enum, e.g., when building bitmasks. This adds a helper function to `AMREX_ENUM`.
1 parent d44e926 commit dbc02ed

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
@@ -128,6 +128,17 @@ namespace amrex
128128
{
129129
return std::string(ET::class_name);
130130
}
131+
132+
/** Return the underlying (u)int of an enum value
133+
*
134+
* Useful when building bitmasks.
135+
*/
136+
template <typename T, typename ET = amrex_enum_traits<T>,
137+
std::enable_if_t<ET::value,int> = 0>
138+
constexpr auto getEnumUnderlyingValue (T v) noexcept
139+
{
140+
return static_cast<std::underlying_type_t<T>>(v);
141+
}
131142
}
132143

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

0 commit comments

Comments
 (0)