This commit was manufactured by cvs2svn to create branch 'gomp-branch'.
[official-gcc.git] / libstdc++-v3 / include / bits / type_traits.h
blob0a263e5e0b6f6b500529f657ba730e142f55e3f6
1 // Type traits implementation -*- C++ -*-
3 // Copyright (C) 2001, 2004 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
32 * Copyright (c) 1997
33 * Silicon Graphics Computer Systems, Inc.
35 * Permission to use, copy, modify, distribute and sell this software
36 * and its documentation for any purpose is hereby granted without fee,
37 * provided that the above copyright notice appear in all copies and
38 * that both that copyright notice and this permission notice appear
39 * in supporting documentation. Silicon Graphics makes no
40 * representations about the suitability of this software for any
41 * purpose. It is provided "as is" without express or implied warranty.
44 /** @file type_traits.h
45 * This is an internal header file, included by other library headers.
46 * You should not attempt to use it directly.
49 #ifndef _TYPE_TRAITS_H
50 #define _TYPE_TRAITS_H 1
52 #pragma GCC system_header
54 #include <bits/c++config.h>
57 This header file provides a framework for allowing compile time dispatch
58 based on type attributes. This is useful when writing template code.
59 For example, when making a copy of an array of an unknown type, it helps
60 to know if the type has a trivial copy constructor or not, to help decide
61 if a memcpy can be used.
63 The class template __type_traits provides a series of typedefs each of
64 which is either __true_type or __false_type. The argument to
65 __type_traits can be any type. The typedefs within this template will
66 attain their correct values by one of these means:
67 1. The general instantiation contain conservative values which work
68 for all types.
69 2. Specializations may be declared to make distinctions between types.
70 3. Some compilers (such as the Silicon Graphics N32 and N64 compilers)
71 will automatically provide the appropriate specializations for all
72 types.
74 EXAMPLE:
76 //Copy an array of elements which have non-trivial copy constructors
77 template <class _Tp> void
78 copy(_Tp* __source,_Tp* __destination,int __n,__false_type);
79 //Copy an array of elements which have trivial copy constructors. Use memcpy.
80 template <class _Tp> void
81 copy(_Tp* __source,_Tp* __destination,int __n,__true_type);
83 //Copy an array of any type by using the most efficient copy mechanism
84 template <class _Tp> inline void copy(_Tp* __source,_Tp* __destination,int __n) {
85 copy(__source,__destination,__n,
86 typename __type_traits<_Tp>::has_trivial_copy_constructor());
90 struct __true_type {};
91 struct __false_type {};
93 template <class _Tp>
94 struct __type_traits
96 typedef __true_type this_dummy_member_must_be_first;
97 /* Do not remove this member. It informs a compiler which
98 automatically specializes __type_traits that this
99 __type_traits template is special. It just makes sure that
100 things work if an implementation is using a template
101 called __type_traits for something unrelated. */
103 /* The following restrictions should be observed for the sake of
104 compilers which automatically produce type specific specializations
105 of this class:
106 - You may reorder the members below if you wish
107 - You may remove any of the members below if you wish
108 - You must not rename members without making the corresponding
109 name change in the compiler
110 - Members you add will be treated like regular members unless
111 you add the appropriate support in the compiler. */
114 typedef __false_type has_trivial_default_constructor;
115 typedef __false_type has_trivial_copy_constructor;
116 typedef __false_type has_trivial_assignment_operator;
117 typedef __false_type has_trivial_destructor;
118 typedef __false_type is_POD_type;
122 // Provide some specializations.
124 template<>
125 struct __type_traits<bool>
127 typedef __true_type has_trivial_default_constructor;
128 typedef __true_type has_trivial_copy_constructor;
129 typedef __true_type has_trivial_assignment_operator;
130 typedef __true_type has_trivial_destructor;
131 typedef __true_type is_POD_type;
134 template<>
135 struct __type_traits<char>
137 typedef __true_type has_trivial_default_constructor;
138 typedef __true_type has_trivial_copy_constructor;
139 typedef __true_type has_trivial_assignment_operator;
140 typedef __true_type has_trivial_destructor;
141 typedef __true_type is_POD_type;
144 template<>
145 struct __type_traits<signed char>
147 typedef __true_type has_trivial_default_constructor;
148 typedef __true_type has_trivial_copy_constructor;
149 typedef __true_type has_trivial_assignment_operator;
150 typedef __true_type has_trivial_destructor;
151 typedef __true_type is_POD_type;
154 template<>
155 struct __type_traits<unsigned char>
157 typedef __true_type has_trivial_default_constructor;
158 typedef __true_type has_trivial_copy_constructor;
159 typedef __true_type has_trivial_assignment_operator;
160 typedef __true_type has_trivial_destructor;
161 typedef __true_type is_POD_type;
164 template<>
165 struct __type_traits<wchar_t>
167 typedef __true_type has_trivial_default_constructor;
168 typedef __true_type has_trivial_copy_constructor;
169 typedef __true_type has_trivial_assignment_operator;
170 typedef __true_type has_trivial_destructor;
171 typedef __true_type is_POD_type;
174 template<>
175 struct __type_traits<short>
177 typedef __true_type has_trivial_default_constructor;
178 typedef __true_type has_trivial_copy_constructor;
179 typedef __true_type has_trivial_assignment_operator;
180 typedef __true_type has_trivial_destructor;
181 typedef __true_type is_POD_type;
184 template<>
185 struct __type_traits<unsigned short>
187 typedef __true_type has_trivial_default_constructor;
188 typedef __true_type has_trivial_copy_constructor;
189 typedef __true_type has_trivial_assignment_operator;
190 typedef __true_type has_trivial_destructor;
191 typedef __true_type is_POD_type;
194 template<>
195 struct __type_traits<int>
197 typedef __true_type has_trivial_default_constructor;
198 typedef __true_type has_trivial_copy_constructor;
199 typedef __true_type has_trivial_assignment_operator;
200 typedef __true_type has_trivial_destructor;
201 typedef __true_type is_POD_type;
204 template<>
205 struct __type_traits<unsigned int>
207 typedef __true_type has_trivial_default_constructor;
208 typedef __true_type has_trivial_copy_constructor;
209 typedef __true_type has_trivial_assignment_operator;
210 typedef __true_type has_trivial_destructor;
211 typedef __true_type is_POD_type;
214 template<>
215 struct __type_traits<long>
217 typedef __true_type has_trivial_default_constructor;
218 typedef __true_type has_trivial_copy_constructor;
219 typedef __true_type has_trivial_assignment_operator;
220 typedef __true_type has_trivial_destructor;
221 typedef __true_type is_POD_type;
224 template<>
225 struct __type_traits<unsigned long>
227 typedef __true_type has_trivial_default_constructor;
228 typedef __true_type has_trivial_copy_constructor;
229 typedef __true_type has_trivial_assignment_operator;
230 typedef __true_type has_trivial_destructor;
231 typedef __true_type is_POD_type;
234 template<>
235 struct __type_traits<long long>
237 typedef __true_type has_trivial_default_constructor;
238 typedef __true_type has_trivial_copy_constructor;
239 typedef __true_type has_trivial_assignment_operator;
240 typedef __true_type has_trivial_destructor;
241 typedef __true_type is_POD_type;
244 template<>
245 struct __type_traits<unsigned long long>
247 typedef __true_type has_trivial_default_constructor;
248 typedef __true_type has_trivial_copy_constructor;
249 typedef __true_type has_trivial_assignment_operator;
250 typedef __true_type has_trivial_destructor;
251 typedef __true_type is_POD_type;
254 template<>
255 struct __type_traits<float>
257 typedef __true_type has_trivial_default_constructor;
258 typedef __true_type has_trivial_copy_constructor;
259 typedef __true_type has_trivial_assignment_operator;
260 typedef __true_type has_trivial_destructor;
261 typedef __true_type is_POD_type;
264 template<>
265 struct __type_traits<double>
267 typedef __true_type has_trivial_default_constructor;
268 typedef __true_type has_trivial_copy_constructor;
269 typedef __true_type has_trivial_assignment_operator;
270 typedef __true_type has_trivial_destructor;
271 typedef __true_type is_POD_type;
274 template<>
275 struct __type_traits<long double>
277 typedef __true_type has_trivial_default_constructor;
278 typedef __true_type has_trivial_copy_constructor;
279 typedef __true_type has_trivial_assignment_operator;
280 typedef __true_type has_trivial_destructor;
281 typedef __true_type is_POD_type;
284 template <class _Tp>
285 struct __type_traits<_Tp*>
287 typedef __true_type has_trivial_default_constructor;
288 typedef __true_type has_trivial_copy_constructor;
289 typedef __true_type has_trivial_assignment_operator;
290 typedef __true_type has_trivial_destructor;
291 typedef __true_type is_POD_type;
294 // The following could be written in terms of numeric_limits.
295 // We're doing it separately to reduce the number of dependencies.
297 template <class _Tp>
298 struct _Is_integer
300 typedef __false_type _Integral;
303 template<>
304 struct _Is_integer<bool>
306 typedef __true_type _Integral;
309 template<>
310 struct _Is_integer<char>
312 typedef __true_type _Integral;
315 template<>
316 struct _Is_integer<signed char>
318 typedef __true_type _Integral;
321 template<>
322 struct _Is_integer<unsigned char>
324 typedef __true_type _Integral;
327 template<>
328 struct _Is_integer<wchar_t>
330 typedef __true_type _Integral;
333 template<>
334 struct _Is_integer<short>
336 typedef __true_type _Integral;
339 template<>
340 struct _Is_integer<unsigned short>
342 typedef __true_type _Integral;
345 template<>
346 struct _Is_integer<int>
348 typedef __true_type _Integral;
351 template<>
352 struct _Is_integer<unsigned int>
354 typedef __true_type _Integral;
357 template<>
358 struct _Is_integer<long>
360 typedef __true_type _Integral;
363 template<>
364 struct _Is_integer<unsigned long>
366 typedef __true_type _Integral;
369 template<>
370 struct _Is_integer<long long>
372 typedef __true_type _Integral;
375 template<>
376 struct _Is_integer<unsigned long long>
378 typedef __true_type _Integral;
381 #endif /* _TYPE_TRAITS_H */
383 // Local Variables:
384 // mode:C++
385 // End: