Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
_meta_other.h
Go to the documentation of this file.
1
30#ifndef _RWSTD_RW_META_OTHER_H_INCLUDED
31#define _RWSTD_RW_META_OTHER_H_INCLUDED
32
33#include <rw/_defs.h>
34
35#include <rw/_meta_cat.h>
36#include <rw/_meta_ref.h>
37#include <rw/_meta_prop.h>
38#include <rw/_meta_ptr.h>
39#include <rw/_static_assert.h>
40
41#include <rw/_static_assert.h>
42
44
45template <bool _Select, class _TypeT, class _TypeU>
46struct __rw_conditional
47{
48 typedef _TypeT type;
49};
50
51template <class _TypeT, class _TypeU>
52struct __rw_conditional<false, _TypeT, _TypeU>
53{
54 typedef _TypeU type;
55};
56
57#define _RWSTD_CONDITIONAL(C,T,U) _RW::__rw_conditional<C,T,U>::type
58
59
60#ifndef _RWSTD_NO_ALIGN_TRAITS
61
62// Helper for __rw_default_alignment. The member value will evaluate
63// to the nearest power of two that is a valid alignment value that
64// is less than or equal to _Size.
65template <_RWSTD_SIZE_T _Size, _RWSTD_SIZE_T _N,
66 bool = (_RWSTD_TT_MAX_ALIGNMENT <= _N * 2)
67 || (_Size < _N * 2)>
68struct __rw_default_alignment_impl
69{
70 enum { value = __rw_default_alignment_impl<_Size, _N * 2>::value };
71};
72
73// Helper for __rw_default_alignment. The member value will evaluate
74// to the nearest power of two that is less than or equal to _Size.
75// This specialization is used to terminate recursion. It is only used
76// when when _Done in the primary template evaluates is true.
77template <_RWSTD_SIZE_T _Size, _RWSTD_SIZE_T _N>
78struct __rw_default_alignment_impl<_Size, _N, true>
79{
80 enum { value = _N };
81};
82
83
84// Helper for __rw_aligned_storage. The value member shall be the most
85// most stringent alignment requirement for any C++ object whose size
86// is no greater than _Size. This implementation will set value to be
87// the nearest power of two value that is less than or equal to _Size.
88template <_RWSTD_SIZE_T _Size>
89struct __rw_default_alignment
90{
91 enum { value = __rw_default_alignment_impl<_Size, 1>::value };
92};
93
94#ifdef __GNUG__
95
96template <_RWSTD_SIZE_T _Size,
97 _RWSTD_SIZE_T _Align = __rw_default_alignment<_Size>::value>
98struct __rw_aligned_storage
99{
100 typedef struct {
101 _RWSTD_TT_ALIGNED_POD (_Align) _C_align;
102 unsigned char _C_size [_Size];
103 } type;
104};
105
106#else // !__GNUG__
107
108// Helper for __rw_aligned_storage.
109template <_RWSTD_SIZE_T _Align>
110struct __rw_aligned_storage_impl;
111
112#define _RWSTD_ALIGNED_STORAGE_SPEC(N) \
113 template <> struct __rw_aligned_storage_impl<N> { \
114 typedef _RWSTD_TT_ALIGNED_POD (N) _C_type; };
115
121
122#if (32 <= _RWSTD_TT_MAX_ALIGNMENT)
124#endif
125
126#if (64 <= _RWSTD_TT_MAX_ALIGNMENT)
128#endif
129
130#if (128 <= _RWSTD_TT_MAX_ALIGNMENT)
132#endif
133
134#if (256 <= _RWSTD_TT_MAX_ALIGNMENT)
136#endif
137
138#if (512 <= _RWSTD_TT_MAX_ALIGNMENT)
140#endif
141
142#if (1024 <= _RWSTD_TT_MAX_ALIGNMENT)
144#endif
145
146#if (2048 <= _RWSTD_TT_MAX_ALIGNMENT)
148#endif
149
150#if (4096 <= _RWSTD_TT_MAX_ALIGNMENT)
152#endif
153
154#if (8192 <= _RWSTD_TT_MAX_ALIGNMENT)
156#endif
157
158template <_RWSTD_SIZE_T _Size,
159 _RWSTD_SIZE_T _Align = __rw_default_alignment<_Size>::value>
160struct __rw_aligned_storage
161{
162 typedef union {
163 typename
164 __rw_aligned_storage_impl<_Align>::_C_type _C_align;
165
166 unsigned char _C_size [_Size];
167 } type;
168};
169
170#endif // !__GNUG__
171
172
173#ifndef _RWSTD_NO_VARIADIC_TEMPLATES
174
175// Helper for __rw_aligned_union. Provides a typedef type that
176// is the largest type in the sequence of provided types.
177template <class... _Types>
178struct __rw_biggest;
179
180template <class _TypeT, class... _Types>
181struct __rw_biggest<_TypeT, _Types...>
182{
183 enum { _C_values = __rw_biggest<_Types...>::_C_value,
184 _C_value = sizeof (_TypeT) < _C_values
185 ? _C_values
186 : sizeof (_TypeT) };
187};
188
189template <class _TypeT>
190struct __rw_biggest<_TypeT>
191{
192 enum { _C_value = sizeof (_TypeT) };
193};
194
195// Helper for __rw_aligned_union.
196template <class... _Types>
197struct __rw_strictest;
198
199template <class _TypeT, class... _Types>
200struct __rw_strictest<_TypeT, _Types...>
201{
202 enum { _C_values = __rw_strictest<_Types...>::_C_value,
203 _C_value = __rw_alignment_of<_TypeT>::value < _C_values
204 ? _C_values
205 : __rw_alignment_of<_TypeT>::value };
206};
207
208template <class _TypeT>
209struct __rw_strictest<_TypeT>
210{
211 enum { _C_value = __rw_alignment_of<_TypeT>::value };
212};
213
214template <_RWSTD_SIZE_T _Len, class... _Types>
215struct __rw_aligned_union;
216
217template <_RWSTD_SIZE_T _Len, class _TypeT, class... _Types>
218struct __rw_aligned_union<_Len, _TypeT, _Types...>
219{
220 enum { _C_len_value = _Len,
221 _C_size_value = __rw_biggest<_TypeT, _Types...>::_C_value,
222 _C_align_value = __rw_strictest<_TypeT, _Types...>::_C_value };
223
224 typedef typename
225 __rw_aligned_storage< _C_len_value < _C_size_value
226 ? _C_size_value : _C_len_value,
227 _C_align_value>::type type;
228};
229
230#else // _RWSTD_NO_VARIADIC_TEMPLATES
231
232// Helper. Gives the largest of a series of values.
233template <unsigned _A , unsigned _B = 0,
234 unsigned _C = 0, unsigned _D = 0,
235 unsigned _E = 0, unsigned _F = 0,
236 unsigned _G = 0, unsigned _H = 0>
237struct __rw_max_uint
238{
239 enum {
240 _C_ab = _A < _B ? _B : _A,
241 _C_cd = _C < _D ? _D : _C,
242 _C_abcd = _C_ab < _C_cd ? _C_cd : _C_ab,
243
244 _C_ef = _E < _F ? _F : _E,
245 _C_gh = _G < _H ? _H : _G,
246 _C_efgh = _C_ef < _C_gh ? _C_gh : _C_ef,
247
248 _C_value = _C_abcd < _C_efgh ? _C_efgh : _C_abcd
249 };
250};
251
252struct __rw_empty { };
253
254// Helper for __rw_aligned_union.
255template <class _Type1 , class _Type2 = __rw_empty,
256 class _Type3 = __rw_empty, class _Type4 = __rw_empty,
257 class _Type5 = __rw_empty, class _Type6 = __rw_empty,
258 class _Type7 = __rw_empty, class _Type8 = __rw_empty>
259struct __rw_biggest
260{
261 enum { _C_value =
262 __rw_max_uint<sizeof (_Type1), sizeof (_Type2),
263 sizeof (_Type3), sizeof (_Type4),
264 sizeof (_Type5), sizeof (_Type6),
265 sizeof (_Type7), sizeof (_Type8)>::_C_value
266 };
267};
268
269// Helper for __rw_aligned_union.
270template <class _Type1 , class _Type2 = __rw_empty,
271 class _Type3 = __rw_empty, class _Type4 = __rw_empty,
272 class _Type5 = __rw_empty, class _Type6 = __rw_empty,
273 class _Type7 = __rw_empty, class _Type8 = __rw_empty>
274struct __rw_strictest
275{
276 enum { _C_value =
277 __rw_max_uint<__rw_alignment_of<_Type1>::value,
278 __rw_alignment_of<_Type2>::value,
279 __rw_alignment_of<_Type3>::value,
280 __rw_alignment_of<_Type4>::value,
281 __rw_alignment_of<_Type5>::value,
282 __rw_alignment_of<_Type6>::value,
283 __rw_alignment_of<_Type7>::value,
284 __rw_alignment_of<_Type8>::value>::_C_value
285 };
286};
287
288template <_RWSTD_SIZE_T _Len,
289 class _Type1 , class _Type2 = __rw_empty,
290 class _Type3 = __rw_empty, class _Type4 = __rw_empty,
291 class _Type5 = __rw_empty, class _Type6 = __rw_empty,
292 class _Type7 = __rw_empty, class _Type8 = __rw_empty>
293struct __rw_aligned_union
294{
295 enum { _C_len_value = _Len,
296 _C_size_value =
297 __rw_biggest<_Type1, _Type2, _Type3, _Type4,
298 _Type5, _Type6, _Type7, _Type8>::_C_value,
299 _C_align_value =
300 __rw_strictest<_Type1, _Type2, _Type3, _Type4,
301 _Type5, _Type6, _Type7, _Type8>::_C_value
302 };
303
304 typedef typename
305 __rw_aligned_storage< _C_size_value < _C_len_value
306 ? _C_len_value : _C_size_value,
307 _C_align_value>::type type;
308};
309
310#endif // !_RWSTD_NO_VARIADIC_TEMPLATES
311
312#endif // !_RWSTD_NO_ALIGN_TRAITS
313
314
315template <bool _Enable, class _TypeT = void>
316struct __rw_enable_if
317{
318 typedef _TypeT type;
319};
320
321template <class _TypeT>
322struct __rw_enable_if<false, _TypeT>
323{
324};
325
326#define _RWSTD_ENABLE_IF(C,T) _RW::__rw_enable_if<C,T>::type
327
328
329template <bool _Enable, class _TypeT = void>
330struct __rw_disable_if
331{
332 typedef _TypeT type;
333};
334
335template <class _TypeT>
336struct __rw_disable_if<true, _TypeT>
337{
338};
339
340#define _RWSTD_DISABLE_IF(C,T) _RW::__rw_disable_if<C,T>::type
341
342
343template <class _TypeT>
344struct __rw_decay
345{
346private:
347 typedef typename
348 __rw_remove_reference<_TypeT>::type _TypeU;
349
350 typedef typename
351 __rw_conditional<__rw_is_function<_TypeU>::value,
352 typename __rw_add_pointer<_TypeU>::type,
353 typename __rw_remove_cv<_TypeU>::type
354 >::type _TypeV;
355
356public:
357 typedef typename
358 __rw_conditional<__rw_is_array<_TypeU>::value,
359 typename __rw_remove_extent<_TypeU>::type*,
360 _TypeV
361 >::type type;
362};
363
364#define _RWSTD_DECAY(T) _RW::__rw_decay<T>::type
365
366
367} // namespace __rw
368
369
370#endif // _RWSTD_RW_META_OTHER_H_INCLUDED
371
T value(const T &val)
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _RWSTD_ALIGNED_STORAGE_SPEC(N)
#define true
Definition stdbool.h:25
#define false
Definition stdbool.h:26