1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-01 11:39:22 +00:00

AK: Add a CallableAs<R, Args...> concept

This is just the concept version of the IsCallableWithArguments type
trait previously defined in Function.h.
This commit is contained in:
Ali Mohammad Pur 2023-07-08 14:08:25 +03:30 committed by Linus Groh
parent 35599605c1
commit 5a0ad6812c
2 changed files with 28 additions and 17 deletions

View File

@ -129,6 +129,33 @@ concept FallibleFunction = requires(Func&& func, Args&&... args) {
func(forward<Args>(args)...).release_value();
};
}
namespace AK::Detail {
template<typename T, typename Out, typename... Args>
inline constexpr bool IsCallableWithArguments = requires(T t) {
{
t(declval<Args>()...)
} -> Concepts::ConvertibleTo<Out>;
} || requires(T t) {
{
t(declval<Args>()...)
} -> Concepts::SameAs<Out>;
};
}
namespace AK {
using Detail::IsCallableWithArguments;
}
namespace AK::Concepts {
template<typename Func, typename R, typename... Args>
concept CallableAs = Detail::IsCallableWithArguments<Func, R, Args...>;
}
#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;

View File

@ -36,23 +36,6 @@
namespace AK {
namespace Detail {
template<typename T, typename Out, typename... Args>
inline constexpr bool IsCallableWithArguments = requires(T t) {
{
t(declval<Args>()...)
} -> ConvertibleTo<Out>;
} || requires(T t) {
{
t(declval<Args>()...)
} -> SameAs<Out>;
};
}
using Detail::IsCallableWithArguments;
template<typename>
class Function;