-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-callable.cc
More file actions
42 lines (32 loc) · 873 Bytes
/
Copy pathcheck-callable.cc
File metadata and controls
42 lines (32 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <type_traits>
#include <utility>
template <class>
struct check_callable_t;
template <class Ret, class... Arg>
struct check_callable_t<Ret(Arg...)> {
struct fallback {};
struct preferred : fallback {};
template <class F>
constexpr static auto check_impl(F&& f, preferred)
-> decltype(static_cast<Ret>(((F&&)f)(std::declval<Arg>()...)), std::true_type())
{
return {};
}
template <class F>
constexpr static std::false_type check_impl(F&&, fallback)
{
return {};
}
template <class F>
constexpr static auto check(F&& f)
{
return check_callable_t::check_impl((F&&)f, preferred());
}
};
template <class Signature, class F>
constexpr auto check_callable(F&& f)
{
return check_callable_t<Signature>::check((F&&)f);
}
auto result = check_callable<void()>([](auto&&...) {});
static_assert(decltype(result)::value, "");