-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc_traits.h
More file actions
63 lines (48 loc) · 1.56 KB
/
func_traits.h
File metadata and controls
63 lines (48 loc) · 1.56 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#pragma once
#include "is_function.h"
namespace func_traits
{
using size_t = decltype(sizeof(nullptr));
namespace detail
{
template <size_t I, typename... Args>
struct nth_type
{
static_assert(I < sizeof...(Args), "Invalid access to non existent argument!");
using type = nth_type<I - 1, Args...>::type;
};
template <size_t I, typename F, typename... Args>
struct nth_type<I, F, Args...> : nth_type<I - 1, Args...> { };
template <typename F, typename... Args>
struct nth_type<0, F, Args...>
{
using type = F;
};
}
template <bool isPointer, bool isConst, typename R, typename... Args>
struct function
{
using return_type = R;
static constexpr size_t arity = sizeof...(Args);
static constexpr bool is_pointer = isPointer;
static constexpr bool is_const = isConst;
template <size_t i>
struct arg
{
using type = typename detail::nth_type<i, Args...>::type;
};
};
template <typename R>
struct func_traits : public func_traits<decltype(&R::operator())>
{
static constexpr bool is_lambda = true;
};
template <typename R, typename... Args>
struct func_traits<R(Args...)> : public function<false, false, R, Args...> { };
template <typename R, typename... Args>
struct func_traits<R(*)(Args...)> : public function<true, false, R, Args...> { };
template <typename R, typename C, typename... Args>
struct func_traits<R(C::*)(Args...)> : public function<false, true, R, Args...> { };
template <typename R, typename C, typename... Args>
struct func_traits<R(C::*)(Args...) const> : public function<true, true, R, Args...> { };
}