summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-06-15 17:33:47 +0430
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-06-15 22:06:33 +0430
commitf7f88adc78ba708ff8e76cf09549383657074330 (patch)
tree565c5639b9ab53aad03685eb2f6f3b9ceb163893 /AK
parentdac971b4aec2b36864b984929ab52be8f2015c85 (diff)
downloadserenity-f7f88adc78ba708ff8e76cf09549383657074330.zip
AK: Add a function that casts an enum to its underlying type
This is basically the same thing as `std::to_underlying(Enum)`.
Diffstat (limited to 'AK')
-rw-r--r--AK/StdLibExtras.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/AK/StdLibExtras.h b/AK/StdLibExtras.h
index 19411fc4b6..08a5d7a094 100644
--- a/AK/StdLibExtras.h
+++ b/AK/StdLibExtras.h
@@ -110,6 +110,12 @@ constexpr T exchange(T& slot, U&& value)
template<typename T>
using RawPtr = typename Detail::_RawPtr<T>::Type;
+template<typename V>
+constexpr decltype(auto) to_underlying(V value) requires(IsEnum<V>)
+{
+ return static_cast<UnderlyingType<V>>(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;