From f7f88adc78ba708ff8e76cf09549383657074330 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Tue, 15 Jun 2021 17:33:47 +0430 Subject: [PATCH] AK: Add a function that casts an enum to its underlying type This is basically the same thing as `std::to_underlying(Enum)`. --- AK/StdLibExtras.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/AK/StdLibExtras.h b/AK/StdLibExtras.h index 19411fc4b6f..08a5d7a0940 100644 --- a/AK/StdLibExtras.h +++ b/AK/StdLibExtras.h @@ -110,6 +110,12 @@ constexpr T exchange(T& slot, U&& value) template using RawPtr = typename Detail::_RawPtr::Type; +template +constexpr decltype(auto) to_underlying(V value) requires(IsEnum) +{ + return static_cast>(value); +} + } using AK::array_size; @@ -121,3 +127,4 @@ using AK::max; using AK::min; using AK::RawPtr; using AK::swap; +using AK::to_underlying;