summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2022-04-17 09:21:55 +0430
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2022-04-20 00:15:23 +0430
commit2b79f36148f7582b2788cea326849ba5dc119dfe (patch)
tree0fa385cca8604c0b2895d1d785b65cb785710334
parent5d1deac9a8e012e2ab8451e0ce3dace388cdb2eb (diff)
downloadserenity-2b79f36148f7582b2788cea326849ba5dc119dfe.zip
AK: Add a OneOfIgnoringCV concept
Some functions want to ignore cv-qualifiers, and it's much easier to constrain the type through a concept than a separate requires clause on the function.
-rw-r--r--AK/Concepts.h4
-rw-r--r--AK/StdLibExtraDetails.h8
2 files changed, 12 insertions, 0 deletions
diff --git a/AK/Concepts.h b/AK/Concepts.h
index 4cc01a7eb8..7186d6c2ef 100644
--- a/AK/Concepts.h
+++ b/AK/Concepts.h
@@ -39,6 +39,9 @@ concept SameAs = IsSame<T, U>;
template<typename U, typename... Ts>
concept OneOf = IsOneOf<U, Ts...>;
+template<typename U, typename... Ts>
+concept OneOfIgnoringCV = IsOneOfIgnoringCV<U, Ts...>;
+
template<typename T, template<typename...> typename S>
concept SpecializationOf = IsSpecializationOf<T, S>;
@@ -121,6 +124,7 @@ using AK::Concepts::IterableContainer;
using AK::Concepts::IteratorFunction;
using AK::Concepts::IteratorPairWith;
using AK::Concepts::OneOf;
+using AK::Concepts::OneOfIgnoringCV;
using AK::Concepts::SameAs;
using AK::Concepts::Signed;
using AK::Concepts::SpecializationOf;
diff --git a/AK/StdLibExtraDetails.h b/AK/StdLibExtraDetails.h
index 5d0006a205..8bd643436a 100644
--- a/AK/StdLibExtraDetails.h
+++ b/AK/StdLibExtraDetails.h
@@ -593,6 +593,12 @@ inline constexpr bool IsHashCompatible<T, T> = true;
template<typename T, typename... Ts>
inline constexpr bool IsOneOf = (IsSame<T, Ts> || ...);
+template<typename T, typename U>
+inline constexpr bool IsSameIgnoringCV = IsSame<RemoveCV<T>, RemoveCV<U>>;
+
+template<typename T, typename... Ts>
+inline constexpr bool IsOneOfIgnoringCV = (IsSameIgnoringCV<T, Ts> || ...);
+
}
using AK::Detail::AddConst;
using AK::Detail::AddConstToReferencedType;
@@ -630,10 +636,12 @@ using AK::Detail::IsMoveAssignable;
using AK::Detail::IsMoveConstructible;
using AK::Detail::IsNullPointer;
using AK::Detail::IsOneOf;
+using AK::Detail::IsOneOfIgnoringCV;
using AK::Detail::IsPOD;
using AK::Detail::IsPointer;
using AK::Detail::IsRvalueReference;
using AK::Detail::IsSame;
+using AK::Detail::IsSameIgnoringCV;
using AK::Detail::IsSigned;
using AK::Detail::IsSpecializationOf;
using AK::Detail::IsTrivial;