diff options
author | Michel Hermier <michel.hermier@gmail.com> | 2021-03-27 22:12:07 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-28 11:45:51 +0200 |
commit | 4f1c72c174c247f2d3c26c227ddd62bf6c0bf76c (patch) | |
tree | d51cf0fa37d683bc7e678082ddf4c726a3743f00 | |
parent | d77cbc0fa89a2d0efeb213b3c200bf7e7e5d2cb1 (diff) | |
download | serenity-4f1c72c174c247f2d3c26c227ddd62bf6c0bf76c.zip |
AK: Add IsSigned conterpart to IsUnsigned.
-rw-r--r-- | AK/StdLibExtras.h | 4 | ||||
-rw-r--r-- | AK/Tests/TestTypeTraits.cpp | 8 |
2 files changed, 12 insertions, 0 deletions
diff --git a/AK/StdLibExtras.h b/AK/StdLibExtras.h index d4f282cda4..c46ad6e86d 100644 --- a/AK/StdLibExtras.h +++ b/AK/StdLibExtras.h @@ -547,6 +547,9 @@ template<typename... _Ignored> constexpr auto DependentFalse = false; template<typename T> +using IsSigned = IsSame<T, typename MakeSigned<T>::Type>; + +template<typename T> using IsUnsigned = IsSame<T, typename MakeUnsigned<T>::Type>; template<typename T> @@ -623,6 +626,7 @@ using AK::IsFundamental; using AK::IsIntegral; using AK::IsNullPointer; using AK::IsSame; +using AK::IsSigned; using AK::IsUnion; using AK::IsUnsigned; using AK::IsVoid; diff --git a/AK/Tests/TestTypeTraits.cpp b/AK/Tests/TestTypeTraits.cpp index 2e1dbde4c5..1b13d71903 100644 --- a/AK/Tests/TestTypeTraits.cpp +++ b/AK/Tests/TestTypeTraits.cpp @@ -85,6 +85,14 @@ TEST_CASE(FundamentalTypeClassification) EXPECT_TRAIT_FALSE(IsFundamental, Empty, int*, int&); + EXPECT_TRAIT_FALSE(IsSigned, unsigned); + EXPECT_TRAIT_FALSE(IsSigned, unsigned short); + EXPECT_TRAIT_FALSE(IsSigned, unsigned char); + EXPECT_TRAIT_FALSE(IsSigned, unsigned long); + EXPECT_TRAIT_TRUE(IsSigned, int); + EXPECT_TRAIT_TRUE(IsSigned, short); + EXPECT_TRAIT_TRUE(IsSigned, long); + EXPECT_TRAIT_TRUE(IsUnsigned, unsigned); EXPECT_TRAIT_TRUE(IsUnsigned, unsigned short); EXPECT_TRAIT_TRUE(IsUnsigned, unsigned char); |