From dbc02ed889e4d4e5340d05baf85058edd6f4b7f8 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Mon, 18 Aug 2025 12:47:46 -0700 Subject: [PATCH] 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`. --- Src/Base/AMReX_Enum.H | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Src/Base/AMReX_Enum.H b/Src/Base/AMReX_Enum.H index b94e30d396e..5c6525e9ffd 100644 --- a/Src/Base/AMReX_Enum.H +++ b/Src/Base/AMReX_Enum.H @@ -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 , + std::enable_if_t = 0> + constexpr auto getEnumUnderlyingValue (T v) noexcept + { + return static_cast>(v); + } } #define AMREX_ENUM(CLASS, ...) \