Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
_typetraits.h
Go to the documentation of this file.
1// -*- C++ -*-
2
34#ifndef _RWSTD_TYPETRAITS_H_INCLUDED
35#define _RWSTD_TYPETRAITS_H_INCLUDED
36
37
38#include <rw/_defs.h>
39
40
42
43template <class T, T v>
44struct __rw_integral_constant
45{
46 static constexpr T value = v;
47 using value_type = T;
48 using type = integral_constant;
49
50 constexpr operator value_type() const noexcept { return value; }
51 constexpr value_type operator()() const noexcept { return value; }
52};
53
54using __rw_true_type = __rw_integral_constant<bool, true>;
55using __rw_false_type = __rw_integral_constant<bool, false>;
56
57template <class _TypeT>
58struct __rw_is_const
59{
60 typedef _TypeT _C_type;
61 enum { _C_val = 0 };
62};
63
64template <class _TypeT>
65struct __rw_is_const<const _TypeT>
66{
67 typedef _TypeT _C_type;
68 enum { _C_val = 1 };
69};
70
71template <class _TypeT>
72struct __rw_is_volatile
73{
74 typedef _TypeT _C_type;
75 enum { _C_val = 0 };
76};
77
78template <class _TypeT>
79struct __rw_is_volatile<volatile _TypeT>
80{
81 typedef _TypeT _C_type;
82 enum { _C_val = 1 };
83};
84
85
86template <class _TypeT>
87struct __rw_is_cv_qualified
88{
89 typedef _TypeT _C_type;
90 enum { _C_val = 0 };
91};
92
93template <class _TypeT>
94struct __rw_is_cv_qualified<const _TypeT>
95{
96 typedef _TypeT _C_type;
97 enum { _C_val = 1 };
98};
99
100template <class _TypeT>
101struct __rw_is_cv_qualified<volatile _TypeT>
102{
103 typedef _TypeT _C_type;
104 enum { _C_val = 1 };
105};
106
107template <class _TypeT>
108struct __rw_is_cv_qualified<const volatile _TypeT>
109{
110 typedef _TypeT _C_type;
111 enum { _C_val = 1 };
112};
113
114
115template <class _TypeT>
116struct __rw_is_pointer
117{
118 typedef _TypeT _C_type;
119 enum { _C_val = 0 };
120};
121
122template <class _TypeT>
123struct __rw_is_pointer<_TypeT*>
124{
125 typedef _TypeT _C_type;
126 enum { _C_val = 1 };
127};
128
129
130template <class _TypeT>
131struct __rw_is_reference
132{
133 typedef _TypeT _C_type;
134 enum { _C_val = 0 };
135};
136
137template <class _TypeT>
138struct __rw_is_reference<_TypeT&>
139{
140 typedef _TypeT _C_type;
141 enum { _C_val = 1 };
142};
143
144template <class _TypeT>
145struct __rw_is_reference<_TypeT&&>
146{
147 typedef _TypeT _C_type;
148 enum { _C_val = 1 };
149};
150
151template <class _TypeT>
152struct __rw_is_fundamental
153{
154 enum { _C_val = __rw_is_pointer<_TypeT>::_C_val };
155};
156
158struct __rw_is_fundamental<unsigned char> { enum { _C_val = 1 }; };
159
161struct __rw_is_fundamental<signed char> { enum { _C_val = 1 }; };
162
164struct __rw_is_fundamental<char> { enum { _C_val = 1 }; };
165
167struct __rw_is_fundamental<unsigned short> { enum { _C_val = 1 }; };
168
170struct __rw_is_fundamental<signed short> { enum { _C_val = 1 }; };
171
173struct __rw_is_fundamental<unsigned int> { enum { _C_val = 1 }; };
174
176struct __rw_is_fundamental<signed int> { enum { _C_val = 1 }; };
177
179struct __rw_is_fundamental<unsigned long> { enum { _C_val = 1 }; };
180
182struct __rw_is_fundamental<signed long> { enum { _C_val = 1 }; };
183
184#ifdef _RWSTD_LONG_LONG
185
187struct __rw_is_fundamental<unsigned _RWSTD_LONG_LONG> { enum { _C_val = 1 }; };
188
190struct __rw_is_fundamental<signed _RWSTD_LONG_LONG> { enum { _C_val = 1 }; };
191
192#endif // _RWSTD_LONG_LONG
193
195struct __rw_is_fundamental<float> { enum { _C_val = 1 }; };
196
198struct __rw_is_fundamental<double> { enum { _C_val = 1 }; };
199
200#ifndef _RWSTD_NO_LONG_DOUBLE
201
203struct __rw_is_fundamental<long double> { enum { _C_val = 1 }; };
204
205#endif // _RWSTD_NO_LONG_DOUBLE
206
207#ifndef _RWSTD_NO_BOOL
208
210struct __rw_is_fundamental<bool> { enum { _C_val = 1 }; };
211
212#endif // _RWSTD_NO_BOOL
213
214#ifndef _RWSTD_NO_NATIVE_WCHAR_T
215
217struct __rw_is_fundamental<wchar_t> { enum { _C_val = 1 }; };
218
219#endif // _RWSTD_NO_NATIVE_WCHAR_T
220
222struct __rw_is_fundamental<void> { enum { _C_val = 1 }; };
223
224
225template <class _TypeT>
226struct __rw_is_enum
227{
228 struct _C_no { };
229 struct _C_yes { int _C_dummy [2]; };
230
231 struct _C_indirect {
232 // prevent classes with user-defined conversions from matching
233
234 // use double to prevent float->int gcc conversion warnings
235 _C_indirect (double);
236 };
237
238 // nested struct gets rid of bogus gcc errors
239 struct _C_nest {
240 // supply first argument to prevent HP aCC warnings
241 static _C_no _C_is (int, ...);
242 static _C_yes _C_is (int, _C_indirect);
243
244 static _TypeT _C_make_T ();
245 };
246
247#if !defined (__HP_aCC) || __HP_aCC > 33000
248
249 enum {
250 _C_val = sizeof (_C_yes)
251 == sizeof (_C_nest::_C_is (0, _C_nest::_C_make_T ()))
252 && !__rw_is_fundamental<_TypeT>::_C_val
253 };
254
255#else
256
257 // prevent references from causing an error
258 typedef typename __rw_is_reference<_TypeT>::_C_type _C_type;
259
260 // working around an HP aCC bug (see PR #25347)
261 // NOTE: this fails for classes due to another bug (PR #25384)
262 static const bool
263 _C_val = sizeof (_C_yes) == sizeof (_C_nest::_C_is (0, _C_type ()))
264 && !__rw_is_fundamental<_TypeT>::_C_val;
265
266#endif // __HP_aCC > 33000
267
268};
269
270
271#if defined (__HP_aCC) && __HP_aCC <= 33000
272
273template <class _TypeT>
274const bool __rw_is_enum<_TypeT>::_C_val;
275
276#endif // __HP_aCC <= 33000
277
278
280struct __rw_is_enum<void>
281{
282 enum { _C_val = 0 };
283};
284
285
286template <class _TypeT>
287struct __rw_type_traits
288{
289 typedef typename __rw_is_const<_TypeT>::_C_type _C_non_const_type;
290 typedef typename __rw_is_volatile<_TypeT>::_C_type _C_non_volatile_type;
291 typedef typename __rw_is_pointer<_TypeT>::_C_type _C_non_pointer_type;
292 typedef typename __rw_is_reference<_TypeT>::_C_type _C_non_reference_type;
293
294 typedef typename __rw_is_cv_qualified<_TypeT>::_C_type
295 _C_non_cv_qualified_type;
296
297 enum {
298 _C_is_const = __rw_is_const<_TypeT>::_C_val,
299 _C_is_volatile = __rw_is_volatile<_TypeT>::_C_val,
300 _C_is_cv_qualified = __rw_is_cv_qualified<_TypeT>::_C_val,
301 _C_is_pointer = __rw_is_pointer<_TypeT>::_C_val,
302 _C_is_reference = __rw_is_reference<_TypeT>::_C_val,
303 _C_is_fundamental = __rw_is_fundamental<_TypeT>::_C_val,
304 _C_is_enum = __rw_is_enum<_TypeT>::_C_val,
305 _C_is_class = !_C_is_pointer
306 && !_C_is_reference
307 && !_C_is_fundamental
308 && !_C_is_enum
309 };
310};
311
312
313} // namespace __rw
314
315
316#endif // _RWSTD_TYPETRAITS_H_INCLUDED
#define T
Definition 17.names.cpp:163
#define v
Definition 17.names.cpp:138
T value(const T &val)
#define _RWSTD_SPECIALIZED_CLASS
#define _RWSTD_LONG_LONG
unsigned short wchar_t
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define bool
Definition stdbool.h:24