-
Notifications
You must be signed in to change notification settings - Fork 0
/
c98.hpp
224 lines (182 loc) · 6.47 KB
/
c98.hpp
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#pragma once
namespace sps {
/********** std::remove_cv replacement **********/
template< typename T >
struct remove_const {
typedef T type;
};
template< typename T >
struct remove_const< const T > {
typedef T type;
};
template< typename T >
struct remove_volatile {
typedef T type;
};
template< typename T >
struct remove_volatile< volatile T > {
typedef T type;
};
template< typename T >
struct remove_cv {
typedef typename remove_volatile<typename remove_const<T>::type >::type type;
};
/********** std::is_pointer replacement *********/
template< typename T >
struct is_pointer_helper {
static const bool value = false;
};
template< typename T >
struct is_pointer_helper< T* > {
static const bool value = true;
};
template< typename T >
struct is_pointer {
static const bool value = is_pointer_helper< typename remove_cv< T >::type >::value;
};
/********** std::enable_if replacement **********/
template< bool CONDITION, typename TYPE = void >
struct enable_if {
};
template< typename TYPE >
struct enable_if< true, TYPE > {
typedef TYPE type;
};
/****** std::remove_reference replacement *******/
template< typename T >
struct remove_reference {
typedef T type;
};
template< typename T >
struct remove_reference< T& > {
typedef T type;
};
/******* std::is_constructible replacement ******/
template< typename T, typename AT_1 = void, typename AT_2 = void, typename AT_3 = void, typename AT_4 = void >
class is_constructible_impl {
private:
template< typename C_T, typename C_AT_1,
typename C_AT_2, typename C_AT_3, typename C_AT_4 >
static bool test(
typename sps::enable_if<
sizeof( C_T ) ==
sizeof( C_T(
static_cast< C_AT_1 >( *static_cast< typename sps::remove_reference< C_AT_1 >::type* >( NULL ) ),
static_cast< C_AT_2 >( *static_cast< typename sps::remove_reference< C_AT_2 >::type* >( NULL ) ),
static_cast< C_AT_3 >( *static_cast< typename sps::remove_reference< C_AT_3 >::type* >( NULL ) ),
static_cast< C_AT_4 >( *static_cast< typename sps::remove_reference< C_AT_4 >::type* >( NULL ) )
))
>::type*
);
template< typename, typename, typename, typename, typename >
static int test( ... );
public:
static const bool value = ( sizeof( test< T, AT_1, AT_2, AT_3, AT_4 >( NULL ) ) == sizeof( bool ) );
};
template< typename T, typename AT_1, typename AT_2, typename AT_3 >
class is_constructible_impl< T, AT_1, AT_2, AT_3, void > {
private:
template< typename C_T, typename C_AT_1, typename C_AT_2, typename C_AT_3 >
static bool test(
typename sps::enable_if<
sizeof( C_T ) ==
sizeof( C_T(
static_cast< C_AT_1 >( *static_cast< typename sps::remove_reference< C_AT_1 >::type* >( NULL ) ),
static_cast< C_AT_2 >( *static_cast< typename sps::remove_reference< C_AT_2 >::type* >( NULL ) ),
static_cast< C_AT_3 >( *static_cast< typename sps::remove_reference< C_AT_3 >::type* >( NULL ) )
) )
>::type*
);
template< typename, typename, typename, typename >
static int test( ... );
public:
static const bool value = ( sizeof( test< T, AT_1, AT_2, AT_3 >( NULL ) ) == sizeof( bool ) );
};
template< typename T, typename AT_1, typename AT_2 >
class is_constructible_impl< T, AT_1, AT_2, void, void > {
private:
template< typename C_T, typename C_AT_1, typename C_AT_2 >
static bool test(
typename sps::enable_if<
sizeof( C_T ) ==
sizeof( C_T(
static_cast< C_AT_1 >( *static_cast< typename sps::remove_reference< C_AT_1 >::type* >( NULL ) ),
static_cast< C_AT_2 >( *static_cast< typename sps::remove_reference< C_AT_2 >::type* >( NULL ) )
) )
>::type*
);
template< typename, typename, typename >
static int test( ... );
public:
static const bool value = ( sizeof( test< T, AT_1, AT_2 >( NULL ) ) == sizeof( bool ) );
};
template< typename T, typename AT_1 >
class is_constructible_impl< T, AT_1, void, void, void > {
private:
template< typename C_T, typename C_AT_1 >
static bool test(
typename sps::enable_if<
sizeof( C_T ) ==
sizeof( C_T(
static_cast< C_AT_1 >( *static_cast< typename sps::remove_reference< C_AT_1 >::type* >( NULL ) )
) )
>::type*
);
template< typename, typename >
static int test( ... );
public:
static const bool value = ( sizeof( test< T, AT_1 >( NULL ) ) == sizeof( bool ) );
};
template< typename T >
class is_constructible_impl< T, void, void, void, void > {
private:
template< typename C_T >
static C_T testFun( C_T );
template< typename C_T >
static bool test( typename sps::enable_if< sizeof( C_T ) == sizeof( testFun( C_T() ) ) >::type* );
template< typename >
static int test( ... );
public:
static const bool value = ( sizeof( test< T >( NULL ) ) == sizeof( bool ) );
};
template< typename T, typename AT_1 = void, typename AT_2 = void, typename AT_3 = void, typename AT_4 = void >
class is_constructible_impl_ptr {
public:
static const bool value = false;
};
template< typename T, typename AT_1 >
class is_constructible_impl_ptr< T, AT_1, typename enable_if< is_pointer< typename remove_reference< T >::type >::value, void >::type, void, void > {
private:
template< typename C_T >
static bool test( C_T );
template< typename >
static int test( ... );
public:
static const bool value = ( sizeof( test< T >( static_cast< AT_1 >( NULL ) ) ) == sizeof( bool ) );
};
template< typename T >
class is_constructible_impl_ptr< T, void, void, void, void > {
public:
static const bool value = true;
};
template< typename T, typename AT_1 = void, typename AT_2 = void, typename AT_3 = void, typename AT_4 = void >
class is_constructible {
public:
static const bool value = (
is_pointer< typename remove_reference< T >::type >::value ?
is_constructible_impl_ptr< T, AT_1, AT_2, AT_3, AT_4 >::value :
is_constructible_impl< T, AT_1, AT_2, AT_3, AT_4 >::value);
};
template<class T>
struct is_copy_constructible :
std::is_constructible<T, typename std::add_lvalue_reference<
typename std::add_const<T>::type>::type>> {};
template<class T>
struct is_trivially_copy_constructible :
std::is_trivially_constructible<T, typename std::add_lvalue_reference<
typename std::add_const<T>::type>::type>> {};
template<class T>
struct is_nothrow_copy_constructible :
std::is_nothrow_constructible<T, typename std::add_lvalue_reference<
typename std::add_const<T>::type>::type>> {};
} // namespace sps