shards Version of the Day
Loading...
Searching...
No Matches
Shards_TypeList.hpp
1// @HEADER
2// *****************************************************************************
3// Shards : Shared Discretization Tools
4//
5// Copyright 2008-2011 NTESS and the Shards contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef Shards_TypeList_hpp
11#define Shards_TypeList_hpp
12
13namespace shards {
14
26
27//----------------------------------------------------------------------
32template<typename T1, typename T2>
33struct SameType { enum { value = false }; };
34
35template<typename T>
36struct SameType<T,T> { enum { value = true }; };
37
38//----------------------------------------------------------------------
39
40struct TypeListEnd {};
41
49template< typename Value , class Tail = TypeListEnd > struct TypeList {};
50
51//----------------------------------------------------------------------
56template< class ListType > struct TypeListLength {};
57
58template<>
59struct TypeListLength< TypeListEnd >
60{ enum { value = 0 }; };
61
62template< typename Value , class Tail >
63struct TypeListLength< TypeList< Value , Tail > >
64{ enum { value = 1 + TypeListLength< Tail >::value }; };
65
66//----------------------------------------------------------------------
72template< class ListType, unsigned ordinal > struct TypeListAt {};
73
74template< unsigned ordinal >
75struct TypeListAt< TypeListEnd , ordinal >
76{ typedef TypeListEnd type ; };
77
78template< typename Value , class Tail >
79struct TypeListAt< TypeList< Value , Tail > , 0 >
80{ typedef Value type ; };
81
82template< typename Value , class Tail , unsigned ordinal >
83struct TypeListAt< TypeList< Value , Tail > , ordinal >
84{ typedef typename TypeListAt< Tail , ordinal - 1 >::type type ; };
85
86//----------------------------------------------------------------------
93template< class ListType , typename TestValue , unsigned ordinal = 0 >
94struct TypeListIndex {};
95
96template< typename TestValue , unsigned ordinal >
97struct TypeListIndex< TypeListEnd , TestValue , ordinal >
98{
99 enum { value = -1 };
100};
101
102template< typename Value , class Tail , typename TestValue , unsigned ordinal >
103struct TypeListIndex< TypeList< Value , Tail > , TestValue , ordinal >
104{
105private:
106 enum { match = SameType< Value , TestValue >::value };
107 enum { J = match && 0 < ordinal ? ordinal - 1 : ordinal };
108 enum { N = TypeListIndex< Tail , TestValue , J >::value };
109public:
110 enum { value = match && 0 == ordinal ? 0 : ( -1 == N ? -1 : N + 1 ) };
111};
112
113//----------------------------------------------------------------------
119template< class ListType , typename TestValue >
121
122template< typename TestValue >
123struct TypeListCount< TypeListEnd , TestValue >
124{ enum { value = 0 }; };
125
126template< typename Value , class Tail , typename TestValue >
127struct TypeListCount< TypeList< Value , Tail > , TestValue >
128{
129 enum { value = TypeListCount< Tail , TestValue >::value +
130 ( SameType< Value , TestValue >::value ? 1 : 0 ) };
131};
132
133//----------------------------------------------------------------------
138template< class ListType , typename TestValue > struct TypeListMember {};
139
140template< typename TestValue >
141struct TypeListMember< TypeListEnd , TestValue >
142{ enum { value = false }; };
143
144template< typename Value , class Tail , typename TestValue >
145struct TypeListMember< TypeList< Value , Tail > , TestValue >
146{
147 enum { value = SameType< Value , TestValue >::value ||
148 TypeListMember< Tail , TestValue >::value };
149};
150
151//----------------------------------------------------------------------
156template< class ListType > struct TypeListUnique {};
157
158template<>
159struct TypeListUnique< TypeListEnd >
160{ enum { value = true }; };
161
162template< typename Value , class Tail >
163struct TypeListUnique< TypeList< Value , Tail > >
164{
165 enum { value = ! TypeListMember< Tail , Value >::value &&
166 TypeListUnique< Tail >::value };
167};
168
169//----------------------------------------------------------------------
175template< class ListA , class ListB > struct TypeListDisjoint {};
176
177template< class ListB >
178struct TypeListDisjoint< TypeListEnd , ListB >
179{ enum { value = true }; };
180
181template< typename Value , class Tail , class ListB >
182struct TypeListDisjoint< TypeList< Value , Tail > , ListB >
183{
184 enum { value = ! TypeListMember< ListB , Value >::value &&
185 TypeListDisjoint< Tail , ListB >::value };
186};
187
188//----------------------------------------------------------------------
193template< class ListType > struct TypeListFirst {};
194
195template<>
196struct TypeListFirst< TypeListEnd >
197{ typedef TypeListEnd type ; };
198
199template< typename Value , class Tail >
200struct TypeListFirst< TypeList< Value , Tail > >
201{ typedef Value type ; };
202
203//----------------------------------------------------------------------
208template< class ListType > struct TypeListLast {};
209
210template<>
211struct TypeListLast< TypeListEnd >
212{ typedef TypeListEnd type ; };
213
214template< typename Value >
215struct TypeListLast< TypeList< Value , TypeListEnd > >
216{ typedef Value type ; };
217
218template< typename Value , class Tail >
219struct TypeListLast< TypeList< Value , Tail > >
220{ typedef typename TypeListLast< Tail >::type type ; };
221
222//----------------------------------------------------------------------
227template< class ListA , typename T > struct TypeListAppend {};
228
229template<>
230struct TypeListAppend< TypeListEnd , TypeListEnd >
231{ typedef TypeListEnd type ; };
232
233template< typename T >
234struct TypeListAppend< TypeListEnd , T >
235{ typedef TypeList< T > type ; };
236
237template< typename Value , class Tail , typename T >
238struct TypeListAppend< TypeList< Value , Tail > , T >
239{
240 typedef TypeList< Value , typename TypeListAppend< Tail , T >::type > type ;
241};
242
243//----------------------------------------------------------------------
248template< class ListA , class ListB > struct TypeListJoin {};
249
250template<>
251struct TypeListJoin< TypeListEnd , TypeListEnd >
252{ typedef TypeListEnd type ; };
253
254template< typename Value , class Tail >
255struct TypeListJoin< TypeListEnd , TypeList< Value , Tail > >
256{ typedef TypeList< Value , Tail > type ; };
257
258template< typename ValueA , class TailA , typename ValueB , class TailB >
259struct TypeListJoin< TypeList< ValueA , TailA > ,
260 TypeList< ValueB , TailB > >
261{
262private:
263 typedef typename
264 TypeListJoin< TailA , TypeList< ValueB , TailB > >::type Tail ;
265public:
266 typedef TypeList< ValueA , Tail > type ;
267};
268
269//----------------------------------------------------------------------
274template< class ListType, unsigned ordinal > struct TypeListEraseAt {};
275
276template< typename Value , class Tail >
277struct TypeListEraseAt< TypeList< Value , Tail > , 0 >
278{ typedef Tail type ; };
279
280template< typename Value , class Tail , unsigned ordinal >
281struct TypeListEraseAt< TypeList< Value , Tail > , ordinal >
282{
283 typedef TypeList< Value ,
284 typename TypeListEraseAt<Tail,ordinal-1>::type > type ;
285};
286
287//----------------------------------------------------------------------
294template< class ListType > struct TypeListClean {};
295
296template<>
297struct TypeListClean< TypeListEnd >
298{ typedef TypeListEnd type ; };
299
300template< class Tail >
301struct TypeListClean< TypeList< TypeListEnd , Tail > >
302{ typedef TypeListEnd type ; };
303
304template< typename Value , class Tail >
305struct TypeListClean< TypeList< Value , Tail > >
306{
307 typedef TypeList< Value , typename TypeListClean< Tail >::type > type ;
308};
309
310//----------------------------------------------------------------------
315template< typename T00 = TypeListEnd ,
316 typename T01 = TypeListEnd ,
317 typename T02 = TypeListEnd ,
318 typename T03 = TypeListEnd ,
319 typename T04 = TypeListEnd ,
320 typename T05 = TypeListEnd ,
321 typename T06 = TypeListEnd ,
322 typename T07 = TypeListEnd ,
323 typename T08 = TypeListEnd ,
324 typename T09 = TypeListEnd ,
325 typename T10 = TypeListEnd ,
326 typename T11 = TypeListEnd ,
327 typename T12 = TypeListEnd ,
328 typename T13 = TypeListEnd ,
329 typename T14 = TypeListEnd ,
330 typename T15 = TypeListEnd ,
331 typename T16 = TypeListEnd ,
332 typename T17 = TypeListEnd ,
333 typename T18 = TypeListEnd ,
334 typename T19 = TypeListEnd ,
335 typename T20 = TypeListEnd ,
336 typename T21 = TypeListEnd ,
337 typename T22 = TypeListEnd ,
338 typename T23 = TypeListEnd ,
339 typename T24 = TypeListEnd ,
340 typename T25 = TypeListEnd ,
341 typename T26 = TypeListEnd ,
342 typename T27 = TypeListEnd ,
343 typename T28 = TypeListEnd ,
344 typename T29 = TypeListEnd ,
345 typename T30 = TypeListEnd ,
346 typename T31 = TypeListEnd ,
347 typename T32 = TypeListEnd ,
348 typename T33 = TypeListEnd ,
349 typename T34 = TypeListEnd ,
350 typename T35 = TypeListEnd ,
351 typename T36 = TypeListEnd ,
352 typename T37 = TypeListEnd ,
353 typename T38 = TypeListEnd ,
354 typename T39 = TypeListEnd ,
355 typename T40 = TypeListEnd ,
356 typename T41 = TypeListEnd ,
357 typename T42 = TypeListEnd ,
358 typename T43 = TypeListEnd ,
359 typename T44 = TypeListEnd ,
360 typename T45 = TypeListEnd ,
361 typename T46 = TypeListEnd ,
362 typename T47 = TypeListEnd ,
363 typename T48 = TypeListEnd ,
364 typename T49 = TypeListEnd ,
365 typename T50 = TypeListEnd ,
366 typename T51 = TypeListEnd ,
367 typename T52 = TypeListEnd ,
368 typename T53 = TypeListEnd ,
369 typename T54 = TypeListEnd ,
370 typename T55 = TypeListEnd ,
371 typename T56 = TypeListEnd ,
372 typename T57 = TypeListEnd ,
373 typename T58 = TypeListEnd ,
374 typename T59 = TypeListEnd ,
375 typename T60 = TypeListEnd ,
376 typename T61 = TypeListEnd ,
377 typename T62 = TypeListEnd ,
378 typename T63 = TypeListEnd >
380{
381#ifndef DOXYGEN_COMPILE
382private:
383 typedef TypeList< T00 ,
384 TypeList< T01 ,
385 TypeList< T02 ,
386 TypeList< T03 ,
387 TypeList< T04 ,
388 TypeList< T05 ,
389 TypeList< T06 ,
390 TypeList< T07 ,
391 TypeList< T08 ,
392 TypeList< T09 ,
393 TypeList< T10 ,
394 TypeList< T11 ,
395 TypeList< T12 ,
396 TypeList< T13 ,
397 TypeList< T14 ,
398 TypeList< T15 ,
399 TypeList< T16 ,
400 TypeList< T17 ,
401 TypeList< T18 ,
402 TypeList< T19 ,
403 TypeList< T20 ,
404 TypeList< T21 ,
405 TypeList< T22 ,
406 TypeList< T23 ,
407 TypeList< T24 ,
408 TypeList< T25 ,
409 TypeList< T26 ,
410 TypeList< T27 ,
411 TypeList< T28 ,
412 TypeList< T29 ,
413 TypeList< T30 ,
414 TypeList< T31 ,
415 TypeList< T32 ,
416 TypeList< T33 ,
417 TypeList< T34 ,
418 TypeList< T35 ,
419 TypeList< T36 ,
420 TypeList< T37 ,
421 TypeList< T38 ,
422 TypeList< T39 ,
423 TypeList< T40 ,
424 TypeList< T41 ,
425 TypeList< T42 ,
426 TypeList< T43 ,
427 TypeList< T44 ,
428 TypeList< T45 ,
429 TypeList< T46 ,
430 TypeList< T47 ,
431 TypeList< T48 ,
432 TypeList< T49 ,
433 TypeList< T50 ,
434 TypeList< T51 ,
435 TypeList< T52 ,
436 TypeList< T53 ,
437 TypeList< T54 ,
438 TypeList< T55 ,
439 TypeList< T56 ,
440 TypeList< T57 ,
441 TypeList< T58 ,
442 TypeList< T59 ,
443 TypeList< T60 ,
444 TypeList< T61 ,
445 TypeList< T62 ,
446 TypeList< T63 ,
447 TypeListEnd > > > > > > > > > > > > > > > >
448 > > > > > > > > > > > > > > > >
449 > > > > > > > > > > > > > > > >
450 > > > > > > > > > > > > > > > > dirty_type ;
451#endif /* DOXYGEN_COMPILE */
452public:
453
456
458 enum { length = TypeListLength<type>::value };
459
461 enum { unique = TypeListUnique<type>::value };
462};
463
465} // namespace shards
466
467#endif // Shards_TypeList_hpp
468
Member typedef ... type ; is a type list constructed from the template arguments.
TypeListClean< dirty_type >::type type
The constructed type list.
Member enum { value = ... }; is true if T1 and T2 are the same type.
Member typedef ... type ; is defined by appending T to the end of ListA .
Member typedef ... type ; is the type of the member of ListType at location ordinal if ordinal...
Member typedef ... type ; is defined by truncating ListType at the first occurance of TypeListEn...
Member enum { value = ... }; is the number of occurances of TestValue within ListType .
Member enum { value = ... }; is true if all members of ListA are not a member ListB .
Member typedef ... type ; is defined by erasing member at ordinal from ListType .
Member typedef ... type ; is the first member of ListType .
Member enum { value = ... }; is the location within ListType of occurance I of type TestValue ...
Member typedef ... type ; is defined by joining ListB to the end of ListA .
Member typedef ... type ; is the last member of ListType .
Member enum { value = ... }; is the length of the type list.
Member enum { value = ... }; is true if TestValue is a member of ListType .
Member enum { value = ... }; is true if each member of ListType appears exactly once.
A link within a linked list of types.