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
Notes: sideshowbarker 2024-07-17 02:28:18 +09:00
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(); 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 #if !USING_AK_GLOBALLY
@ -136,6 +163,7 @@ namespace AK {
#endif #endif
using AK::Concepts::Arithmetic; using AK::Concepts::Arithmetic;
using AK::Concepts::ArrayLike; using AK::Concepts::ArrayLike;
using AK::Concepts::CallableAs;
using AK::Concepts::ConvertibleTo; using AK::Concepts::ConvertibleTo;
using AK::Concepts::DerivedFrom; using AK::Concepts::DerivedFrom;
using AK::Concepts::Enum; using AK::Concepts::Enum;

View file

@ -36,23 +36,6 @@
namespace AK { 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> template<typename>
class Function; class Function;