1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:17:44 +00:00

AK: Add a CommonType<Ts...> type trait

Also adds a simple-ish test for CommonType.
This commit is contained in:
Ali Mohammad Pur 2021-07-22 19:01:05 +04:30 committed by Andreas Kling
parent ccd19d464e
commit 6c9ef20010
2 changed files with 45 additions and 3 deletions

View file

@ -319,6 +319,30 @@ struct __MakeSigned<char> {
template<typename T>
using MakeSigned = typename __MakeSigned<T>::Type;
template<typename T>
auto declval() -> T;
template<typename...>
struct __CommonType;
template<typename T>
struct __CommonType<T> {
using Type = T;
};
template<typename T1, typename T2>
struct __CommonType<T1, T2> {
using Type = decltype(true ? declval<T1>() : declval<T2>());
};
template<typename T1, typename T2, typename... Ts>
struct __CommonType<T1, T2, Ts...> {
using Type = typename __CommonType<typename __CommonType<T1, T2>::Type, Ts...>::Type;
};
template<typename... Ts>
using CommonType = typename __CommonType<Ts...>::Type;
template<class T>
inline constexpr bool IsVoid = IsSame<void, RemoveCV<T>>;
@ -457,9 +481,6 @@ inline constexpr bool IsTrivial = __is_trivial(T);
template<typename T>
inline constexpr bool IsTriviallyCopyable = __is_trivially_copyable(T);
template<typename T>
auto declval() -> T;
template<typename T, typename... Args>
inline constexpr bool IsCallableWithArguments = requires(T t) { t(declval<Args>()...); };
@ -515,6 +536,7 @@ inline constexpr bool IsTriviallyMoveAssignable = IsTriviallyAssignable<AddLvalu
using AK::Detail::AddConst;
using AK::Detail::AddLvalueReference;
using AK::Detail::AddRvalueReference;
using AK::Detail::CommonType;
using AK::Detail::Conditional;
using AK::Detail::CopyConst;
using AK::Detail::declval;