-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP454.FunctionType.cpp
More file actions
44 lines (37 loc) · 962 Bytes
/
P454.FunctionType.cpp
File metadata and controls
44 lines (37 loc) · 962 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
43
44
#include <type_traits>
template<typename... Args>
struct TypeList {};
template<typename T>
struct IsFunction : std::false_type {};
template<typename R, typename... Args>
struct IsFunction<R(Args...)> : std::true_type
{
using RetType = R;
using Params = TypeList<Args...>;
static constexpr bool variadic = false;
};
template<typename R, typename... Args>
struct IsFunction<R(Args..., ...)> : std::true_type
{
using RetType = R;
using Params = TypeList<Args...>;
static constexpr bool variadic = true; // C-style varargs
};
template<typename T>
constexpr bool IsFunction_v = IsFunction<T>::value;
void f();
int add(int a, int b);
int sum(int a, int b, ...);
struct X
{
void f();
int add(int a, int b);
void g() const;
};
int main(int argc, char const *argv[])
{
static_assert(IsFunction_v<decltype(f)>);
static_assert(IsFunction_v<decltype(add)>);
static_assert(IsFunction_v<decltype(sum)>);
return 0;
}