From 33a978444300302c6c513502a60a7ff260456064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sun, 4 May 2025 18:18:33 +0100 Subject: [PATCH] src: simplify is_callable by making it a concept Using a C++20 `concept` here makes `is_callable` much simpler than relying on SFINAE. It is equivalent for function types, `std::function`, lambdas, and classes with `operator()`, regardless of argument or return types. --- src/req_wrap-inl.h | 2 +- src/util.h | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/req_wrap-inl.h b/src/req_wrap-inl.h index bfcb13b9036310..ac0ca8921a1e51 100644 --- a/src/req_wrap-inl.h +++ b/src/req_wrap-inl.h @@ -111,7 +111,7 @@ struct CallLibuvFunction { template struct MakeLibuvRequestCallback { static T For(ReqWrap* req_wrap, T v) { - static_assert(!is_callable::value, + static_assert(!is_callable, "MakeLibuvRequestCallback missed a callback"); return v; } diff --git a/src/util.h b/src/util.h index 7e575605cb7364..081d7c53f922fa 100644 --- a/src/util.h +++ b/src/util.h @@ -689,13 +689,9 @@ class NonCopyableMaybe { }; // Test whether some value can be called with (). -template -struct is_callable : std::is_function { }; - template -struct is_callable::value - >::type> : std::true_type { }; +concept is_callable = + std::is_function::value || requires { &T::operator(); }; template struct FunctionDeleter {