mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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. PR-URL: https://github.com/nodejs/node/pull/58169 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
This commit is contained in:
@@ -111,7 +111,7 @@ struct CallLibuvFunction<ReqT, void(*)(ReqT*, Args...)> {
|
||||
template <typename ReqT, typename T>
|
||||
struct MakeLibuvRequestCallback {
|
||||
static T For(ReqWrap<ReqT>* req_wrap, T v) {
|
||||
static_assert(!is_callable<T>::value,
|
||||
static_assert(!is_callable<T>,
|
||||
"MakeLibuvRequestCallback missed a callback");
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -661,13 +661,9 @@ struct MallocedBuffer {
|
||||
};
|
||||
|
||||
// Test whether some value can be called with ().
|
||||
template <typename T, typename = void>
|
||||
struct is_callable : std::is_function<T> { };
|
||||
|
||||
template <typename T>
|
||||
struct is_callable<T, typename std::enable_if<
|
||||
std::is_same<decltype(void(&T::operator())), void>::value
|
||||
>::type> : std::true_type { };
|
||||
concept is_callable =
|
||||
std::is_function<T>::value || requires { &T::operator(); };
|
||||
|
||||
template <typename T, void (*function)(T*)>
|
||||
struct FunctionDeleter {
|
||||
|
||||
Reference in New Issue
Block a user