diff --git a/AK/Function.h b/AK/Function.h index 5c9f690c91..76777e416b 100644 --- a/AK/Function.h +++ b/AK/Function.h @@ -38,10 +38,16 @@ namespace AK { namespace Detail { -template +template inline constexpr bool IsCallableWithArguments = requires(T t) { - t(declval()...); - }; + { + t(declval()...) + } -> ConvertibleTo; + } || requires(T t) { + { + t(declval()...) + } -> SameAs; + }; } using Detail::IsCallableWithArguments; @@ -75,14 +81,14 @@ public: template Function(CallableType&& callable) - requires((IsFunctionObject && IsCallableWithArguments && !IsSame, Function>)) + requires((IsFunctionObject && IsCallableWithArguments && !IsSame, Function>)) { init_with_callable(forward(callable)); } template Function(FunctionType f) - requires((IsFunctionPointer && IsCallableWithArguments, In...> && !IsSame, Function>)) + requires((IsFunctionPointer && IsCallableWithArguments, Out, In...> && !IsSame, Function>)) { init_with_callable(move(f)); } @@ -109,7 +115,7 @@ public: template Function& operator=(CallableType&& callable) - requires((IsFunctionObject && IsCallableWithArguments)) + requires((IsFunctionObject && IsCallableWithArguments)) { clear(); init_with_callable(forward(callable)); @@ -118,7 +124,7 @@ public: template Function& operator=(FunctionType f) - requires((IsFunctionPointer && IsCallableWithArguments, In...>)) + requires((IsFunctionPointer && IsCallableWithArguments, Out, In...>)) { clear(); if (f) diff --git a/Userland/Libraries/LibJS/SafeFunction.h b/Userland/Libraries/LibJS/SafeFunction.h index 7a86dc95c9..0db4df7dd4 100644 --- a/Userland/Libraries/LibJS/SafeFunction.h +++ b/Userland/Libraries/LibJS/SafeFunction.h @@ -51,14 +51,14 @@ public: template SafeFunction(CallableType&& callable) - requires((AK::IsFunctionObject && IsCallableWithArguments && !IsSame, SafeFunction>)) + requires((AK::IsFunctionObject && IsCallableWithArguments && !IsSame, SafeFunction>)) { init_with_callable(forward(callable), CallableKind::FunctionObject); } template SafeFunction(FunctionType f) - requires((AK::IsFunctionPointer && IsCallableWithArguments, In...> && !IsSame, SafeFunction>)) + requires((AK::IsFunctionPointer && IsCallableWithArguments, Out, In...> && !IsSame, SafeFunction>)) { init_with_callable(move(f), CallableKind::FunctionPointer); } @@ -85,7 +85,7 @@ public: template SafeFunction& operator=(CallableType&& callable) - requires((AK::IsFunctionObject && IsCallableWithArguments)) + requires((AK::IsFunctionObject && IsCallableWithArguments)) { clear(); init_with_callable(forward(callable)); @@ -94,7 +94,7 @@ public: template SafeFunction& operator=(FunctionType f) - requires((AK::IsFunctionPointer && IsCallableWithArguments, In...>)) + requires((AK::IsFunctionPointer && IsCallableWithArguments, Out, In...>)) { clear(); if (f) diff --git a/Userland/Libraries/LibXML/Parser/Parser.cpp b/Userland/Libraries/LibXML/Parser/Parser.cpp index ea348178e8..334b82a61e 100644 --- a/Userland/Libraries/LibXML/Parser/Parser.cpp +++ b/Userland/Libraries/LibXML/Parser/Parser.cpp @@ -242,7 +242,7 @@ ErrorOr Parser::expect(StringView expected) } template -requires(IsCallableWithArguments) ErrorOr Parser::expect(Pred predicate, StringView description) +requires(IsCallableWithArguments) ErrorOr Parser::expect(Pred predicate, StringView description) { auto rollback = rollback_point(); auto start = m_lexer.tell(); @@ -257,7 +257,7 @@ requires(IsCallableWithArguments) ErrorOr Pa } template -requires(IsCallableWithArguments) ErrorOr Parser::expect_many(Pred predicate, StringView description) +requires(IsCallableWithArguments) ErrorOr Parser::expect_many(Pred predicate, StringView description) { auto rollback = rollback_point(); auto start = m_lexer.tell(); diff --git a/Userland/Libraries/LibXML/Parser/Parser.h b/Userland/Libraries/LibXML/Parser/Parser.h index fc6f39714b..eec1b01e19 100644 --- a/Userland/Libraries/LibXML/Parser/Parser.h +++ b/Userland/Libraries/LibXML/Parser/Parser.h @@ -139,9 +139,9 @@ private: ErrorOr expect(StringView); template - requires(IsCallableWithArguments) ErrorOr expect(Pred, StringView description); + requires(IsCallableWithArguments) ErrorOr expect(Pred, StringView description); template - requires(IsCallableWithArguments) ErrorOr expect_many(Pred, StringView description); + requires(IsCallableWithArguments) ErrorOr expect_many(Pred, StringView description); static size_t s_debug_indent_level; [[nodiscard]] auto rollback_point(SourceLocation location = SourceLocation::current())