1 // tr1common internal header
2 #ifndef _TR1_COMMON_
3 #define _TR1_COMMON_
4 #include <yvals.h>
5
6  #if _HAS_TR1
7
8  #else /* _HAS_TR1 */
9   #error TR1 not fully supported
10  #endif /* _HAS_TR1 */
11
12   #define _NO_SFINAE 1
13
14     // maximum number of arguments to call wrappers
15 #define _NMAX 10
16
17 #define _XNAME(x, z)        x ## z
18 #define _YNAME(x, z)        _XNAME(x, z)
19 #define _YNAME15(x, y, z)    _XNAME(x, z) y
20 #define _YNAME2(x, y, z)    _XNAME(x, z) _XNAME(y, z)
21
22 #define _CORE_0(x)
23 #define _CORE15_0(x, y)
24 #define _CORE2_0(x, y)
25 #define _NARGSm1_0            0
26
27 #define _CORE_1(x)
28 #define _CORE15_1(x, y)
29 #define _CORE2_1(x, y)
30 #define _NARGSm1_1            0
31
32 #define _CORE_2(x)
33 #define _CORE15_2(x, y)
34 #define _CORE2_2(x, y)
35 #define _NARGSm1_2            1
36
37 #define _CORE_3(x)            _YNAME(x, 1)
38 #define _CORE15_3(x, y)        _YNAME15(x, y, 1)
39 #define _CORE2_3(x, y)        _YNAME2(x, y, 1)
40 #define _NARGSm1_3            2
41
42 #define _CORE_4(x)            _CORE_3(x), _YNAME(x, 2)
43 #define _CORE15_4(x, y)        _CORE15_3(x, y), _YNAME15(x, y, 2)
44 #define _CORE2_4(x, y)        _CORE2_3(x, y), _YNAME2(x, y, 2)
45 #define _NARGSm1_4            3
46
47 #define _CORE_5(x)            _CORE_4(x), _YNAME(x, 3)
48 #define _CORE15_5(x, y)        _CORE15_4(x, y), _YNAME15(x, y, 3)
49 #define _CORE2_5(x, y)        _CORE2_4(x, y), _YNAME2(x, y, 3)
50 #define _NARGSm1_5            4
51
52 #define _CORE_6(x)            _CORE_5(x), _YNAME(x, 4)
53 #define _CORE15_6(x, y)        _CORE15_5(x, y), _YNAME15(x, y, 4)
54 #define _CORE2_6(x, y)        _CORE2_5(x, y), _YNAME2(x, y, 4)
55 #define _NARGSm1_6            5
56
57 #define _CORE_7(x)            _CORE_6(x), _YNAME(x, 5)
58 #define _CORE15_7(x, y)        _CORE15_6(x, y), _YNAME15(x, y, 5)
59 #define _CORE2_7(x, y)        _CORE2_6(x, y), _YNAME2(x, y, 5)
60 #define _NARGSm1_7            6
61
62 #define _CORE_8(x)            _CORE_7(x), _YNAME(x, 6)
63 #define _CORE15_8(x, y)        _CORE15_7(x, y), _YNAME15(x, y, 6)
64 #define _CORE2_8(x, y)        _CORE2_7(x, y), _YNAME2(x, y, 6)
65 #define _NARGSm1_8            7
66
67 #define _CORE_9(x)            _CORE_8(x), _YNAME(x, 7)
68 #define _CORE15_9(x, y)        _CORE15_8(x, y), _YNAME15(x, y, 7)
69 #define _CORE2_9(x, y)        _CORE2_8(x, y), _YNAME2(x, y, 7)
70 #define _NARGSm1_9            8
71
72 #define _CORE_10(x)            _CORE_9(x), _YNAME(x, 8)
73 #define _CORE15_10(x, y)    _CORE15_9(x, y), _YNAME15(x, y, 8)
74 #define _CORE2_10(x, y)        _CORE2_9(x, y), _YNAME2(x, y, 8)
75 #define _NARGSm1_10            9
76
77 #define _TAIL_10(x)
78 #define _TAIL_9(x)            x
79 #define _TAIL_8(x)            _TAIL_9(x), x
80 #define _TAIL_7(x)            _TAIL_8(x), x
81 #define _TAIL_6(x)            _TAIL_7(x), x
82 #define _TAIL_5(x)            _TAIL_6(x), x
83 #define _TAIL_4(x)            _TAIL_5(x), x
84 #define _TAIL_3(x)            _TAIL_4(x), x
85 #define _TAIL_2(x)            _TAIL_3(x), x
86 #define _TAIL_1(x)            _TAIL_2(x), x
87 #define _TAIL_0(x)            _TAIL_1(x), x
88
89 #define _ARG_MAX            9
90 #define _CDR_MAX(x)            _CORE_10(x), _YNAME(x, _ARG_MAX)
91 #define _CDR15_MAX(x, y)    _CORE15_10(x, y), _YNAME15(x, y, _ARG_MAX)
92 #define _CDR2_MAX(x, y)     _CORE2_10(x, y), _YNAME2(x, y, _ARG_MAX)
93 #define _LIST_MAX(x)        _YNAME(x, 0), _CDR_MAX(x)
94 #define _LIST15_MAX(x, y)    _YNAME15(x, y, 0), _CDR15_MAX(x, y)
95 #define _LIST2_MAX(x, y)     _YNAME2(x, y, 0), _CDR2_MAX(x, y)
96
97 #define _CLASS_ARG0_MAX        _LIST_MAX(class _Arg)
98 #define _CLASS_FARG0_MAX    _LIST_MAX(class _Farg)
99 #define _ARG0_A0_REF_MAX    _LIST2_MAX(_Arg, &_Ax)
100
101 #define _ARG1_ARG2_MAX        _CDR_MAX(_Arg)
102 #define _ARG0_ARG1_MAX        _LIST_MAX(_Arg)
103 #define _FARG1_FARG2_MAX    _CDR_MAX(_Farg)
104 #define _FARG0_FARG1_MAX    _LIST_MAX(_Farg)
105
106 #define _A1_A2_MAX            _CDR_MAX(_Ax)
107 #define _A0_A1_MAX            _LIST_MAX(_Ax)
108
109 #define _NIL_TAIL_MAXm1        _TAIL_1(_Nil)
110 #define _NIL_TAIL_MAX        _TAIL_0(_Nil)
111 #define _TAIL_MAX(x)        _TAIL_0(x)
112 #define _CLASS_ARG0_DEF_MAX    _LIST15_MAX(class _Arg, = _Nil)
113
Lines 114 ... 123 are skipped.
124
125     namespace tr1 {    // TR1 additions
126
127     // TYPE DEFINITIONS
128     // STRUCT _Nil
129 struct _Nil
130     {    // empty struct, for unused argument types
131     };
132 static _Nil _Nil_obj;
133
134     // TEMPLATE integral_constant
135 template<class _Ty,
136     _Ty _Val>
137     struct integral_constant
138     {    // convenient template for integral constant types
139     static const _Ty value = _Val;
140
141     typedef _Ty value_type;
142     typedef integral_constant<_Ty, _Val> type;
143     };
144
145 typedef integral_constant<bool, true> true_type;
146 typedef integral_constant<bool, false> false_type;
147
148     // TEMPLATE CLASS _Or
149 template<bool _First,
150     bool _Second>
151     struct _Or;
152 template<>
153     struct _Or<false, false>
154         : false_type
155         {    // define as false
156         };
157
158 template<>
159     struct _Or<false, true>
160         : true_type
161         {    // define as true
162         };
163
164 template<>
165     struct _Or<true, false>
166         : true_type
167         {    // define as true
168         };
169
170 template<>
171     struct _Or<true, true>
172         : true_type
173         {    // define as true
174         };
175
176     // TEMPLATE _Cat_base
177 template<bool>
178     struct _Cat_base;
179 template<>
180     struct _Cat_base<false>
181     : false_type
182     {    // base class for type predicates
183     };
184
185 template<>
186     struct _Cat_base<true>
187     : true_type
188     {    // base class for type predicates
189     };
190
191     // TEMPLATE CLASS _Is_integral
192 template<class _Ty>
193     struct _Is_integral
194         : false_type
195     {    // determine whether _Ty is integral
196     };
197
198 template<>
199     struct _Is_integral<bool>
200         : true_type
201     {    // determine whether _Ty is integral
202     };
203
204 template<>
205     struct _Is_integral<char>
206         : true_type
207     {    // determine whether _Ty is integral
208     };
209
210 template<>
211     struct _Is_integral<unsigned char>
212         : true_type
213     {    // determine whether _Ty is integral
214     };
215
216 template<>
217     struct _Is_integral<signed char>
218         : true_type
219     {    // determine whether _Ty is integral
220     };
221
222  #ifdef _NATIVE_WCHAR_T_DEFINED
223 template<>
224     struct _Is_integral<wchar_t>
225         : true_type
226     {    // determine whether _Ty is integral
227     };
228  #endif /* _NATIVE_WCHAR_T_DEFINED */
229
230 template<>
231     struct _Is_integral<unsigned short>
232         : true_type
233     {    // determine whether _Ty is integral
234     };
235
236 template<>
237     struct _Is_integral<signed short>
238         : true_type
239     {    // determine whether _Ty is integral
240     };
241
242 template<>
243     struct _Is_integral<unsigned int>
244         : true_type
245     {    // determine whether _Ty is integral
246     };
247
248 template<>
249     struct _Is_integral<signed int>
250         : true_type
251     {    // determine whether _Ty is integral
252     };
253
254 template<>
255     struct _Is_integral<unsigned long>
256         : true_type
257     {    // determine whether _Ty is integral
258     };
259
260 template<>
261     struct _Is_integral<signed long>
262         : true_type
263     {    // determine whether _Ty is integral
264     };
265
266  #ifdef _LONGLONG
267 template<>
268     struct _Is_integral<_LONGLONG>
269         : true_type
270     {    // determine whether _Ty is integral
271     };
272
273 template<>
274     struct _Is_integral<_ULONGLONG>
275         : true_type
276     {    // determine whether _Ty is integral
277     };
278  #endif /* _LONGLONG */
279
280     // TEMPLATE CLASS _Is_floating_point
281 template<class _Ty>
282     struct _Is_floating_point
283         : false_type
284     {    // determine whether _Ty is floating point
285     };
286
287 template<>
288     struct _Is_floating_point<float>
289         : true_type
290     {    // determine whether _Ty is floating point
291     };
292
293 template<>
294     struct _Is_floating_point<double>
295         : true_type
296     {    // determine whether _Ty is floating point
297     };
298
299 template<>
300     struct _Is_floating_point<long double>
301         : true_type
302     {    // determine whether _Ty is floating point
303     };
304
305     // TEMPLATE _Remove_reference
306 template<class _Ty>
307     struct _Remove_reference
308     {    // remove reference
309     typedef _Ty _Type;
310     };
311
312 template<class _Ty>
313     struct _Remove_reference<_Ty&>
314     {    // remove reference
315     typedef _Ty _Type;
316     };
317
318     // MACRO _IS_YES
319 typedef char (&_No)[1];
320 typedef char (&_Yes)[2];
321
322  #define _IS_YES(ty)    (sizeof (ty) == sizeof (_STD tr1::_Yes))
323
324     // FUNCTION _Has_result_type
325 _No _Has_result_type(...);
326
327 template<class _Ty>
328     _Yes _Has_result_type(_Ty *,
329         typename _Remove_reference<typename _Ty::result_type>::_Type * = 0);
330
331 #define _HAS_RESULT_TYPE(_Ty)    \
332     _IS_YES(_STD tr1::_Has_result_type((_Ty *)0))
333     }    // namespace tr1
334 _STD_END
335 #endif /* _TR1_COMMON_ */
336
337 /*
338  * Copyright (c) 1992-2008 by P.J. Plauger.  ALL RIGHTS RESERVED.
339  * Consult your license regarding permissions and restrictions.
340 V5.05:0009 */
341