diff --git a/AK/StdLibExtraDetails.h b/AK/StdLibExtraDetails.h index 0f1cc687d8..748e353dc5 100644 --- a/AK/StdLibExtraDetails.h +++ b/AK/StdLibExtraDetails.h @@ -319,6 +319,30 @@ struct __MakeSigned { template using MakeSigned = typename __MakeSigned::Type; +template +auto declval() -> T; + +template +struct __CommonType; + +template +struct __CommonType { + using Type = T; +}; + +template +struct __CommonType { + using Type = decltype(true ? declval() : declval()); +}; + +template +struct __CommonType { + using Type = typename __CommonType::Type, Ts...>::Type; +}; + +template +using CommonType = typename __CommonType::Type; + template inline constexpr bool IsVoid = IsSame>; @@ -457,9 +481,6 @@ inline constexpr bool IsTrivial = __is_trivial(T); template inline constexpr bool IsTriviallyCopyable = __is_trivially_copyable(T); -template -auto declval() -> T; - template inline constexpr bool IsCallableWithArguments = requires(T t) { t(declval()...); }; @@ -515,6 +536,7 @@ inline constexpr bool IsTriviallyMoveAssignable = IsTriviallyAssignable; + EXPECT_VARIADIC_TRAIT_TRUE(IsSame, TCommon0, float); + + using TCommon1 = CommonType; + EXPECT_VARIADIC_TRAIT_TRUE(IsSame, TCommon1, int); + + struct Foo { + }; + using TCommon2 = CommonType; + EXPECT_VARIADIC_TRAIT_TRUE(IsSame, TCommon2, Foo); + + struct Bar { + operator Foo(); + }; + using TCommon3 = CommonType; + EXPECT_VARIADIC_TRAIT_TRUE(IsSame, TCommon3, Foo); +}