1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:27:45 +00:00

AK: Add global is<T>() and downcast<T>()

Let's unify the is<T>/to<T> implementations that currently exist in
separate versions in LibCore and LibWeb.
This commit is contained in:
Andreas Kling 2020-07-26 16:25:02 +02:00
parent a565121793
commit ce2c5b375c
2 changed files with 114 additions and 0 deletions

View file

@ -107,10 +107,12 @@ template<class T>
struct RemoveConst {
typedef T Type;
};
template<class T>
struct RemoveConst<const T> {
typedef T Type;
};
template<class T>
struct RemoveVolatile {
typedef T Type;
@ -441,6 +443,22 @@ inline constexpr T exchange(T& slot, U&& value)
return old_value;
}
template<typename T>
struct IsUnion : public IntegralConstant<bool, __is_union(T)> {
};
template<typename T>
struct IsClass : public IntegralConstant<bool, __is_class(T)> {
};
template<typename Base, typename Derived>
struct IsBaseOf : public IntegralConstant<bool, __is_base_of(Base, Derived)> {
};
template<typename ReferenceType, typename T>
using CopyConst =
typename Conditional<IsConst<ReferenceType>::value, typename AddConst<T>::Type, typename RemoveConst<T>::Type>::Type;
}
using AK::AddConst;
@ -449,8 +467,11 @@ using AK::clamp;
using AK::Conditional;
using AK::exchange;
using AK::forward;
using AK::IsBaseOf;
using AK::IsClass;
using AK::IsConst;
using AK::IsSame;
using AK::IsUnion;
using AK::IsVoid;
using AK::MakeSigned;
using AK::MakeUnsigned;