Skip to content

Commit 69b5607

Browse files
tniessentargos
authored andcommitted
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: #58169 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 86150f3 commit 69b5607

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

src/req_wrap-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ struct CallLibuvFunction<ReqT, void(*)(ReqT*, Args...)> {
111111
template <typename ReqT, typename T>
112112
struct MakeLibuvRequestCallback {
113113
static T For(ReqWrap<ReqT>* req_wrap, T v) {
114-
static_assert(!is_callable<T>::value,
114+
static_assert(!is_callable<T>,
115115
"MakeLibuvRequestCallback missed a callback");
116116
return v;
117117
}

src/util.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -661,13 +661,9 @@ struct MallocedBuffer {
661661
};
662662

663663
// Test whether some value can be called with ().
664-
template <typename T, typename = void>
665-
struct is_callable : std::is_function<T> { };
666-
667664
template <typename T>
668-
struct is_callable<T, typename std::enable_if<
669-
std::is_same<decltype(void(&T::operator())), void>::value
670-
>::type> : std::true_type { };
665+
concept is_callable =
666+
std::is_function<T>::value || requires { &T::operator(); };
671667

672668
template <typename T, void (*function)(T*)>
673669
struct FunctionDeleter {

0 commit comments

Comments
 (0)