AK: Add a function that casts an enum to its underlying type

This is basically the same thing as `std::to_underlying(Enum)`.
This commit is contained in:
Ali Mohammad Pur 2021-06-15 17:33:47 +04:30 committed by Ali Mohammad Pur
parent dac971b4ae
commit f7f88adc78
Notes: sideshowbarker 2024-07-18 12:13:24 +09:00

View file

@ -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;