From 745a1dbb5dc7201b991bed5afa24892b07dab5f9 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Sun, 27 Jun 2021 23:52:36 +0430 Subject: [PATCH] AK: Add and use the RemoveCVReference type trait --- AK/StdLibExtraDetails.h | 4 ++++ AK/Variant.h | 8 ++++---- Tests/AK/TestTypeTraits.cpp | 8 ++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/AK/StdLibExtraDetails.h b/AK/StdLibExtraDetails.h index 8cf43ebbed5..dca32e33d6c 100644 --- a/AK/StdLibExtraDetails.h +++ b/AK/StdLibExtraDetails.h @@ -195,6 +195,9 @@ struct __RemoveReference { template using RemoveReference = typename __RemoveReference::Type; +template +using RemoveCVReference = RemoveCV>; + template struct __MakeUnsigned { using Type = void; @@ -478,6 +481,7 @@ using AK::Detail::MakeSigned; using AK::Detail::MakeUnsigned; using AK::Detail::RemoveConst; using AK::Detail::RemoveCV; +using AK::Detail::RemoveCVReference; using AK::Detail::RemovePointer; using AK::Detail::RemoveReference; using AK::Detail::RemoveVolatile; diff --git a/AK/Variant.h b/AK/Variant.h index 375e87413dd..9263439ec8c 100644 --- a/AK/Variant.h +++ b/AK/Variant.h @@ -251,7 +251,7 @@ public: using Detail::MergeAndDeduplicatePacks>...>::MergeAndDeduplicatePacks; - template>> + template> void set(T&& t) requires(can_contain()) { constexpr auto new_index = index_of(); @@ -260,7 +260,7 @@ public: m_index = new_index; } - template>> + template> void set(T&& t, Detail::VariantNoClearTag) requires(can_contain()) { constexpr auto new_index = index_of(); @@ -323,7 +323,7 @@ public: { Variant instance { Variant::invalid_index, Detail::VariantConstructTag {} }; visit([&](auto& value) { - if constexpr (Variant::template can_contain>>()) + if constexpr (Variant::template can_contain>()) instance.set(move(value), Detail::VariantNoClearTag {}); }); VERIFY(instance.m_index != instance.invalid_index); @@ -335,7 +335,7 @@ public: { Variant instance { Variant::invalid_index, Detail::VariantConstructTag {} }; visit([&](const auto& value) { - if constexpr (Variant::template can_contain>>()) + if constexpr (Variant::template can_contain>()) instance.set(value, Detail::VariantNoClearTag {}); }); VERIFY(instance.m_index != instance.invalid_index); diff --git a/Tests/AK/TestTypeTraits.cpp b/Tests/AK/TestTypeTraits.cpp index ecea1bfc15f..86b70c88745 100644 --- a/Tests/AK/TestTypeTraits.cpp +++ b/Tests/AK/TestTypeTraits.cpp @@ -105,3 +105,11 @@ TEST_CASE(UnderlyingType) STATIC_EXPECT_EQ(Type, u8); } + +TEST_CASE(RemoveCVReference) +{ + using TestTypeList = TypeList; + using ResultTypeList = TypeList; + + EXPECT_EQ_WITH_TRAIT(RemoveCVReference, TestTypeList, ResultTypeList); +}