mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50: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:
parent
35599605c1
commit
5a0ad6812c
Notes:
sideshowbarker
2024-07-17 02:28:18 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/5a0ad6812c Pull-request: https://github.com/SerenityOS/serenity/pull/19871 Reviewed-by: https://github.com/LucasChollet Reviewed-by: https://github.com/Zaggy1024 ✅
2 changed files with 28 additions and 17 deletions
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue