forked from skyfireitdiy/sflib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsf_meta.h
151 lines (107 loc) · 4.1 KB
/
sf_meta.h
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
* @version 1.0.0
* @author skyfire
* @mail [email protected]
* @see http://github.com/skyfireitdiy/sflib
* @file sf_meta.h
* sflib第一版本发布
* 版本号1.0.0
* 发布日期:2018-10-22
*/
/*
* sf_meta 元编程辅助函数
*/
#pragma once
#include <functional>
#include <tuple>
namespace skyfire {
template<class T>
struct sf_check_param_reference {
};
template<class T, class ... U>
struct sf_check_param_reference<std::function<T(U...)>> {
static constexpr bool value = (std::is_reference<U>::value || ... || false);
};
template<template<typename> class T, typename U, typename...V>
struct sf_check_param_reference<T<U(V...)>> {
static constexpr bool value = (std::is_reference<V>::value || ... || false);
};
template<class T>
struct sf_check_param_pointer {
};
template<class T, class ... U>
struct sf_check_param_pointer<std::function<T(U...)>> {
static constexpr bool value = (std::is_pointer<U>::value || ... || false);
};
template<template<typename> class T, typename U, typename...V>
struct sf_check_param_pointer<T<U(V...)>> {
static constexpr bool value = (std::is_pointer<V>::value || ... || false);
};
template<class T>
struct sf_check_return_reference {
};
template<class T, class ... U>
struct sf_check_return_reference<std::function<T(U...)>> {
static constexpr bool value = std::is_reference<T>::value;
};
template<template<typename> class T, typename U, typename...V>
struct sf_check_return_reference<T<U(V...)>> {
static constexpr bool value = std::is_reference<U>::value;
};
template<class T>
struct sf_check_return_pointer {
};
template<class T, class ... U>
struct sf_check_return_pointer<std::function<T(U...)>> {
static constexpr bool value = std::is_pointer<T>::value;
};
template<template<typename> class T, typename U, typename...V>
struct sf_check_return_pointer<T<U(V...)>> {
static constexpr bool value = std::is_pointer<U>::value;
};
template<class T>
struct sf_function_type_helper {
};
template<class T, class ... U>
struct sf_function_type_helper<std::function<T(U...)>> {
using return_type=T;
using param_type= std::tuple<U...>;
};
template<template<typename> class T, typename U, typename...V>
struct sf_function_type_helper<T<U(V...)>> {
using return_type = U;
using param_type = std::tuple<V...>;
};
template<typename Function, typename Tuple, std::size_t... Index>
decltype(auto) sf_invoke_impl(Function &&func, Tuple &&t, std::index_sequence<Index...>);
template<typename Function, typename Tuple>
decltype(auto) sf_invoke(Function &&func, Tuple &&t);
template<typename _Type, typename Tuple, std::size_t... Index>
_Type *sf_make_obj_from_tuple_impl(Tuple &&t, std::index_sequence<Index...>);
template<typename _Type, typename Tuple>
_Type *sf_make_obj_from_tuple(Tuple &&t);
//////////////////////////////////////////////////////////////////////
template<typename Function, typename Tuple, std::size_t... Index>
decltype(auto) sf_invoke_impl(Function &&func, Tuple &&t, std::index_sequence<Index...>);
template<typename Function, typename Tuple>
decltype(auto) sf_invoke(Function &&func, Tuple &&t);
template<typename _Type, typename Tuple, std::size_t... Index>
_Type *sf_make_obj_from_tuple_impl(Tuple &&t, std::index_sequence<Index...>);
template<typename _Type, typename Tuple>
_Type *sf_make_obj_from_tuple(Tuple &&t);
/////////////////////////////////////////////////////////
// make_placeholders
template<template<int> typename _Placeholders>
struct __sf_placeholders_type {
template<int N>
__sf_placeholders_type(_Placeholders<N>) {};
template<int N>
using type = _Placeholders<N>;
};
template<template<int> typename _Placeholders, int N>
__sf_placeholders_type(_Placeholders<N>)
->
__sf_placeholders_type<_Placeholders>;
template<int N>
auto make_placeholders();
}