From 5a0ad6812c2406dcd3a3611449605b53d8beef0b Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Sat, 8 Jul 2023 14:08:25 +0330 Subject: [PATCH] AK: Add a CallableAs concept This is just the concept version of the IsCallableWithArguments type trait previously defined in Function.h. --- AK/Concepts.h | 28 ++++++++++++++++++++++++++++ AK/Function.h | 17 ----------------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/AK/Concepts.h b/AK/Concepts.h index 461f776472..51f1644f98 100644 --- a/AK/Concepts.h +++ b/AK/Concepts.h @@ -129,6 +129,33 @@ concept FallibleFunction = requires(Func&& func, Args&&... args) { func(forward(args)...).release_value(); }; +} +namespace AK::Detail { + +template +inline constexpr bool IsCallableWithArguments = requires(T t) { + { + t(declval()...) + } -> Concepts::ConvertibleTo; +} || requires(T t) { + { + t(declval()...) + } -> Concepts::SameAs; +}; + +} + +namespace AK { + +using Detail::IsCallableWithArguments; + +} + +namespace AK::Concepts { + +template +concept CallableAs = Detail::IsCallableWithArguments; + } #if !USING_AK_GLOBALLY @@ -136,6 +163,7 @@ namespace AK { #endif using AK::Concepts::Arithmetic; using AK::Concepts::ArrayLike; +using AK::Concepts::CallableAs; using AK::Concepts::ConvertibleTo; using AK::Concepts::DerivedFrom; using AK::Concepts::Enum; diff --git a/AK/Function.h b/AK/Function.h index 90ec3c3752..59a97e8346 100644 --- a/AK/Function.h +++ b/AK/Function.h @@ -36,23 +36,6 @@ namespace AK { -namespace Detail { - -template -inline constexpr bool IsCallableWithArguments = requires(T t) { - { - t(declval()...) - } -> ConvertibleTo; -} || requires(T t) { - { - t(declval()...) - } -> SameAs; -}; - -} - -using Detail::IsCallableWithArguments; - template class Function;