Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4680 right-hear 1
/*
2
 *
3
 * Copyright (c) 1997
4
 * Silicon Graphics Computer Systems, Inc.
5
 *
6
 * Permission to use, copy, modify, distribute and sell this software
7
 * and its documentation for any purpose is hereby granted without fee,
8
 * provided that the above copyright notice appear in all copies and
9
 * that both that copyright notice and this permission notice appear
10
 * in supporting documentation.  Silicon Graphics makes no
11
 * representations about the suitability of this software for any
12
 * purpose.  It is provided "as is" without express or implied warranty.
13
 */
14
 
15
#ifndef _CPP_BITS_TYPE_TRAITS_H
16
#define _CPP_BITS_TYPE_TRAITS_H 1
17
 
18
#pragma GCC system_header
19
 
20
#include 
21
 
22
/*
23
This header file provides a framework for allowing compile time dispatch
24
based on type attributes. This is useful when writing template code.
25
For example, when making a copy of an array of an unknown type, it helps
26
to know if the type has a trivial copy constructor or not, to help decide
27
if a memcpy can be used.
28
 
29
The class template __type_traits provides a series of typedefs each of
30
which is either __true_type or __false_type. The argument to
31
__type_traits can be any type. The typedefs within this template will
32
attain their correct values by one of these means:
33
    1. The general instantiation contain conservative values which work
34
       for all types.
35
    2. Specializations may be declared to make distinctions between types.
36
    3. Some compilers (such as the Silicon Graphics N32 and N64 compilers)
37
       will automatically provide the appropriate specializations for all
38
       types.
39
 
40
EXAMPLE:
41
 
42
//Copy an array of elements which have non-trivial copy constructors
43
template  void
44
  copy(_Tp* __source,_Tp* __destination,int __n,__false_type);
45
//Copy an array of elements which have trivial copy constructors. Use memcpy.
46
template  void
47
  copy(_Tp* __source,_Tp* __destination,int __n,__true_type);
48
 
49
//Copy an array of any type by using the most efficient copy mechanism
50
template  inline void copy(_Tp* __source,_Tp* __destination,int __n) {
51
   copy(__source,__destination,__n,
52
        typename __type_traits<_Tp>::has_trivial_copy_constructor());
53
}
54
*/
55
 
56
 
57
template  struct _Bool {};
58
typedef _Bool  __true_type;
59
typedef _Bool __false_type;
60
 
61
template 
62
struct __type_traits {
63
   typedef __true_type     this_dummy_member_must_be_first;
64
                   /* Do not remove this member. It informs a compiler which
65
                      automatically specializes __type_traits that this
66
                      __type_traits template is special. It just makes sure that
67
                      things work if an implementation is using a template
68
                      called __type_traits for something unrelated. */
69
 
70
   /* The following restrictions should be observed for the sake of
71
      compilers which automatically produce type specific specializations
72
      of this class:
73
          - You may reorder the members below if you wish
74
          - You may remove any of the members below if you wish
75
          - You must not rename members without making the corresponding
76
            name change in the compiler
77
          - Members you add will be treated like regular members unless
78
            you add the appropriate support in the compiler. */
79
 
80
 
81
   typedef __false_type    has_trivial_default_constructor;
82
   typedef __false_type    has_trivial_copy_constructor;
83
   typedef __false_type    has_trivial_assignment_operator;
84
   typedef __false_type    has_trivial_destructor;
85
   typedef __false_type    is_POD_type;
86
};
87
 
88
 
89
// Provide some specializations.
90
 
91
template<> struct __type_traits {
92
   typedef __true_type    has_trivial_default_constructor;
93
   typedef __true_type    has_trivial_copy_constructor;
94
   typedef __true_type    has_trivial_assignment_operator;
95
   typedef __true_type    has_trivial_destructor;
96
   typedef __true_type    is_POD_type;
97
};
98
 
99
template<> struct __type_traits {
100
   typedef __true_type    has_trivial_default_constructor;
101
   typedef __true_type    has_trivial_copy_constructor;
102
   typedef __true_type    has_trivial_assignment_operator;
103
   typedef __true_type    has_trivial_destructor;
104
   typedef __true_type    is_POD_type;
105
};
106
 
107
template<> struct __type_traits {
108
   typedef __true_type    has_trivial_default_constructor;
109
   typedef __true_type    has_trivial_copy_constructor;
110
   typedef __true_type    has_trivial_assignment_operator;
111
   typedef __true_type    has_trivial_destructor;
112
   typedef __true_type    is_POD_type;
113
};
114
 
115
template<> struct __type_traits {
116
   typedef __true_type    has_trivial_default_constructor;
117
   typedef __true_type    has_trivial_copy_constructor;
118
   typedef __true_type    has_trivial_assignment_operator;
119
   typedef __true_type    has_trivial_destructor;
120
   typedef __true_type    is_POD_type;
121
};
122
 
123
template<> struct __type_traits {
124
   typedef __true_type    has_trivial_default_constructor;
125
   typedef __true_type    has_trivial_copy_constructor;
126
   typedef __true_type    has_trivial_assignment_operator;
127
   typedef __true_type    has_trivial_destructor;
128
   typedef __true_type    is_POD_type;
129
};
130
 
131
template<> struct __type_traits {
132
   typedef __true_type    has_trivial_default_constructor;
133
   typedef __true_type    has_trivial_copy_constructor;
134
   typedef __true_type    has_trivial_assignment_operator;
135
   typedef __true_type    has_trivial_destructor;
136
   typedef __true_type    is_POD_type;
137
};
138
 
139
template<> struct __type_traits {
140
   typedef __true_type    has_trivial_default_constructor;
141
   typedef __true_type    has_trivial_copy_constructor;
142
   typedef __true_type    has_trivial_assignment_operator;
143
   typedef __true_type    has_trivial_destructor;
144
   typedef __true_type    is_POD_type;
145
};
146
 
147
template<> struct __type_traits {
148
   typedef __true_type    has_trivial_default_constructor;
149
   typedef __true_type    has_trivial_copy_constructor;
150
   typedef __true_type    has_trivial_assignment_operator;
151
   typedef __true_type    has_trivial_destructor;
152
   typedef __true_type    is_POD_type;
153
};
154
 
155
template<> struct __type_traits {
156
   typedef __true_type    has_trivial_default_constructor;
157
   typedef __true_type    has_trivial_copy_constructor;
158
   typedef __true_type    has_trivial_assignment_operator;
159
   typedef __true_type    has_trivial_destructor;
160
   typedef __true_type    is_POD_type;
161
};
162
 
163
template<> struct __type_traits {
164
   typedef __true_type    has_trivial_default_constructor;
165
   typedef __true_type    has_trivial_copy_constructor;
166
   typedef __true_type    has_trivial_assignment_operator;
167
   typedef __true_type    has_trivial_destructor;
168
   typedef __true_type    is_POD_type;
169
};
170
 
171
template<> struct __type_traits {
172
   typedef __true_type    has_trivial_default_constructor;
173
   typedef __true_type    has_trivial_copy_constructor;
174
   typedef __true_type    has_trivial_assignment_operator;
175
   typedef __true_type    has_trivial_destructor;
176
   typedef __true_type    is_POD_type;
177
};
178
 
179
#ifdef _GLIBCPP_USE_LONG_LONG
180
 
181
template<> struct __type_traits {
182
   typedef __true_type    has_trivial_default_constructor;
183
   typedef __true_type    has_trivial_copy_constructor;
184
   typedef __true_type    has_trivial_assignment_operator;
185
   typedef __true_type    has_trivial_destructor;
186
   typedef __true_type    is_POD_type;
187
};
188
 
189
template<> struct __type_traits {
190
   typedef __true_type    has_trivial_default_constructor;
191
   typedef __true_type    has_trivial_copy_constructor;
192
   typedef __true_type    has_trivial_assignment_operator;
193
   typedef __true_type    has_trivial_destructor;
194
   typedef __true_type    is_POD_type;
195
};
196
 
197
#endif /* _GLIBCPP_USE_LONG_LONG */
198
 
199
template<> struct __type_traits {
200
   typedef __true_type    has_trivial_default_constructor;
201
   typedef __true_type    has_trivial_copy_constructor;
202
   typedef __true_type    has_trivial_assignment_operator;
203
   typedef __true_type    has_trivial_destructor;
204
   typedef __true_type    is_POD_type;
205
};
206
 
207
template<> struct __type_traits {
208
   typedef __true_type    has_trivial_default_constructor;
209
   typedef __true_type    has_trivial_copy_constructor;
210
   typedef __true_type    has_trivial_assignment_operator;
211
   typedef __true_type    has_trivial_destructor;
212
   typedef __true_type    is_POD_type;
213
};
214
 
215
template<> struct __type_traits {
216
   typedef __true_type    has_trivial_default_constructor;
217
   typedef __true_type    has_trivial_copy_constructor;
218
   typedef __true_type    has_trivial_assignment_operator;
219
   typedef __true_type    has_trivial_destructor;
220
   typedef __true_type    is_POD_type;
221
};
222
 
223
template 
224
struct __type_traits<_Tp*> {
225
   typedef __true_type    has_trivial_default_constructor;
226
   typedef __true_type    has_trivial_copy_constructor;
227
   typedef __true_type    has_trivial_assignment_operator;
228
   typedef __true_type    has_trivial_destructor;
229
   typedef __true_type    is_POD_type;
230
};
231
 
232
 
233
// The following could be written in terms of numeric_limits.
234
// We're doing it separately to reduce the number of dependencies.
235
 
236
template  struct _Is_integer {
237
  typedef __false_type _Integral;
238
};
239
 
240
template<> struct _Is_integer {
241
  typedef __true_type _Integral;
242
};
243
 
244
template<> struct _Is_integer {
245
  typedef __true_type _Integral;
246
};
247
 
248
template<> struct _Is_integer {
249
  typedef __true_type _Integral;
250
};
251
 
252
template<> struct _Is_integer {
253
  typedef __true_type _Integral;
254
};
255
 
256
template<> struct _Is_integer {
257
  typedef __true_type _Integral;
258
};
259
 
260
template<> struct _Is_integer {
261
  typedef __true_type _Integral;
262
};
263
 
264
template<> struct _Is_integer {
265
  typedef __true_type _Integral;
266
};
267
 
268
template<> struct _Is_integer {
269
  typedef __true_type _Integral;
270
};
271
 
272
template<> struct _Is_integer {
273
  typedef __true_type _Integral;
274
};
275
 
276
template<> struct _Is_integer {
277
  typedef __true_type _Integral;
278
};
279
 
280
template<> struct _Is_integer {
281
  typedef __true_type _Integral;
282
};
283
 
284
#ifdef _GLIBCPP_USE_LONG_LONG
285
 
286
template<> struct _Is_integer {
287
  typedef __true_type _Integral;
288
};
289
 
290
template<> struct _Is_integer {
291
  typedef __true_type _Integral;
292
};
293
 
294
#endif /* _GLIBCPP_USE_LONG_LONG */
295
 
296
template struct _Is_normal_iterator {
297
   typedef __false_type _Normal;
298
};
299
 
300
// Forward declaration hack, should really include this from somewhere.
301
namespace std {
302
   template class __normal_iterator;
303
};
304
 
305
template
306
struct _Is_normal_iterator< std::__normal_iterator<_Iterator, _Container> > {
307
   typedef __true_type _Normal;
308
};
309
 
310
#endif /* _CPP_BITS_TYPE_TRAITS_H */
311
 
312
// Local Variables:
313
// mode:C++
314
// End: