File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -220,6 +220,26 @@ namespace StormByte {
220220 template <typename E>
221221 concept ScopedEnum = std::is_scoped_enum_v<E>;
222222
223+ /* *
224+ * @brief Alias type giving the underlying integer type of an enum `E`.
225+ *
226+ * Usage:
227+ * enum class Foo : uint16_t { A };
228+ * Type::underlying_type<Foo> value = 0;
229+ */
230+ template <typename E>
231+ requires Enum<E>
232+ using underlying_type = std::underlying_type_t <std::remove_cv_t <E>>;
233+
234+ /* *
235+ * @brief Convert an enum value to its underlying integer representation.
236+ */
237+ template <typename E>
238+ requires Enum<E>
239+ constexpr underlying_type<E> to_underlying (E e) noexcept {
240+ return static_cast <underlying_type<E>>(e);
241+ }
242+
223243 /* *
224244 * @brief Concept to check if a type is a pointer.
225245 * @tparam T Type to check.
You can’t perform that action at this time.
0 commit comments