shards  Version of the Day
 All Classes Functions Variables Typedefs Enumerations Enumerator Groups
Shards_TypeList.hpp
1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Shards : Shared Discretization Tools
6 // Copyright 2008 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Carter Edwards (hcedwar@sandia.gov),
39 // Pavel Bochev (pbboche@sandia.gov), or
40 // Denis Ridzal (dridzal@sandia.gov).
41 //
42 // ************************************************************************
43 //@HEADER
44 */
45 
46 #ifndef Shards_TypeList_hpp
47 #define Shards_TypeList_hpp
48 
49 namespace shards {
50 
63 //----------------------------------------------------------------------
68 template<typename T1, typename T2>
69 struct SameType { enum { value = false }; };
70 
71 template<typename T>
72 struct SameType<T,T> { enum { value = true }; };
73 
74 //----------------------------------------------------------------------
75 
76 struct TypeListEnd {};
77 
85 template< typename Value , class Tail = TypeListEnd > struct TypeList {};
86 
87 //----------------------------------------------------------------------
92 template< class ListType > struct TypeListLength {};
93 
94 template<>
95 struct TypeListLength< TypeListEnd >
96 { enum { value = 0 }; };
97 
98 template< typename Value , class Tail >
99 struct TypeListLength< TypeList< Value , Tail > >
100 { enum { value = 1 + TypeListLength< Tail >::value }; };
101 
102 //----------------------------------------------------------------------
108 template< class ListType, unsigned ordinal > struct TypeListAt {};
109 
110 template< unsigned ordinal >
111 struct TypeListAt< TypeListEnd , ordinal >
112 { typedef TypeListEnd type ; };
113 
114 template< typename Value , class Tail >
115 struct TypeListAt< TypeList< Value , Tail > , 0 >
116 { typedef Value type ; };
117 
118 template< typename Value , class Tail , unsigned ordinal >
119 struct TypeListAt< TypeList< Value , Tail > , ordinal >
120 { typedef typename TypeListAt< Tail , ordinal - 1 >::type type ; };
121 
122 //----------------------------------------------------------------------
129 template< class ListType , typename TestValue , unsigned ordinal = 0 >
130 struct TypeListIndex {};
131 
132 template< typename TestValue , unsigned ordinal >
133 struct TypeListIndex< TypeListEnd , TestValue , ordinal >
134 {
135  enum { value = -1 };
136 };
137 
138 template< typename Value , class Tail , typename TestValue , unsigned ordinal >
139 struct TypeListIndex< TypeList< Value , Tail > , TestValue , ordinal >
140 {
141 private:
142  enum { match = SameType< Value , TestValue >::value };
143  enum { J = match && 0 < ordinal ? ordinal - 1 : ordinal };
144  enum { N = TypeListIndex< Tail , TestValue , J >::value };
145 public:
146  enum { value = match && 0 == ordinal ? 0 : ( -1 == N ? -1 : N + 1 ) };
147 };
148 
149 //----------------------------------------------------------------------
155 template< class ListType , typename TestValue >
156 struct TypeListCount {};
157 
158 template< typename TestValue >
159 struct TypeListCount< TypeListEnd , TestValue >
160 { enum { value = 0 }; };
161 
162 template< typename Value , class Tail , typename TestValue >
163 struct TypeListCount< TypeList< Value , Tail > , TestValue >
164 {
165  enum { value = TypeListCount< Tail , TestValue >::value +
166  ( SameType< Value , TestValue >::value ? 1 : 0 ) };
167 };
168 
169 //----------------------------------------------------------------------
174 template< class ListType , typename TestValue > struct TypeListMember {};
175 
176 template< typename TestValue >
177 struct TypeListMember< TypeListEnd , TestValue >
178 { enum { value = false }; };
179 
180 template< typename Value , class Tail , typename TestValue >
181 struct TypeListMember< TypeList< Value , Tail > , TestValue >
182 {
183  enum { value = SameType< Value , TestValue >::value ||
184  TypeListMember< Tail , TestValue >::value };
185 };
186 
187 //----------------------------------------------------------------------
192 template< class ListType > struct TypeListUnique {};
193 
194 template<>
195 struct TypeListUnique< TypeListEnd >
196 { enum { value = true }; };
197 
198 template< typename Value , class Tail >
199 struct TypeListUnique< TypeList< Value , Tail > >
200 {
201  enum { value = ! TypeListMember< Tail , Value >::value &&
202  TypeListUnique< Tail >::value };
203 };
204 
205 //----------------------------------------------------------------------
211 template< class ListA , class ListB > struct TypeListDisjoint {};
212 
213 template< class ListB >
214 struct TypeListDisjoint< TypeListEnd , ListB >
215 { enum { value = true }; };
216 
217 template< typename Value , class Tail , class ListB >
218 struct TypeListDisjoint< TypeList< Value , Tail > , ListB >
219 {
220  enum { value = ! TypeListMember< ListB , Value >::value &&
221  TypeListDisjoint< Tail , ListB >::value };
222 };
223 
224 //----------------------------------------------------------------------
229 template< class ListType > struct TypeListFirst {};
230 
231 template<>
232 struct TypeListFirst< TypeListEnd >
233 { typedef TypeListEnd type ; };
234 
235 template< typename Value , class Tail >
236 struct TypeListFirst< TypeList< Value , Tail > >
237 { typedef Value type ; };
238 
239 //----------------------------------------------------------------------
244 template< class ListType > struct TypeListLast {};
245 
246 template<>
247 struct TypeListLast< TypeListEnd >
248 { typedef TypeListEnd type ; };
249 
250 template< typename Value >
251 struct TypeListLast< TypeList< Value , TypeListEnd > >
252 { typedef Value type ; };
253 
254 template< typename Value , class Tail >
255 struct TypeListLast< TypeList< Value , Tail > >
256 { typedef typename TypeListLast< Tail >::type type ; };
257 
258 //----------------------------------------------------------------------
263 template< class ListA , typename T > struct TypeListAppend {};
264 
265 template<>
266 struct TypeListAppend< TypeListEnd , TypeListEnd >
267 { typedef TypeListEnd type ; };
268 
269 template< typename T >
270 struct TypeListAppend< TypeListEnd , T >
271 { typedef TypeList< T > type ; };
272 
273 template< typename Value , class Tail , typename T >
274 struct TypeListAppend< TypeList< Value , Tail > , T >
275 {
276  typedef TypeList< Value , typename TypeListAppend< Tail , T >::type > type ;
277 };
278 
279 //----------------------------------------------------------------------
284 template< class ListA , class ListB > struct TypeListJoin {};
285 
286 template<>
287 struct TypeListJoin< TypeListEnd , TypeListEnd >
288 { typedef TypeListEnd type ; };
289 
290 template< typename Value , class Tail >
291 struct TypeListJoin< TypeListEnd , TypeList< Value , Tail > >
292 { typedef TypeList< Value , Tail > type ; };
293 
294 template< typename ValueA , class TailA , typename ValueB , class TailB >
295 struct TypeListJoin< TypeList< ValueA , TailA > ,
296  TypeList< ValueB , TailB > >
297 {
298 private:
299  typedef typename
300  TypeListJoin< TailA , TypeList< ValueB , TailB > >::type Tail ;
301 public:
302  typedef TypeList< ValueA , Tail > type ;
303 };
304 
305 //----------------------------------------------------------------------
310 template< class ListType, unsigned ordinal > struct TypeListEraseAt {};
311 
312 template< typename Value , class Tail >
313 struct TypeListEraseAt< TypeList< Value , Tail > , 0 >
314 { typedef Tail type ; };
315 
316 template< typename Value , class Tail , unsigned ordinal >
317 struct TypeListEraseAt< TypeList< Value , Tail > , ordinal >
318 {
319  typedef TypeList< Value ,
320  typename TypeListEraseAt<Tail,ordinal-1>::type > type ;
321 };
322 
323 //----------------------------------------------------------------------
330 template< class ListType > struct TypeListClean {};
331 
332 template<>
333 struct TypeListClean< TypeListEnd >
334 { typedef TypeListEnd type ; };
335 
336 template< class Tail >
337 struct TypeListClean< TypeList< TypeListEnd , Tail > >
338 { typedef TypeListEnd type ; };
339 
340 template< typename Value , class Tail >
341 struct TypeListClean< TypeList< Value , Tail > >
342 {
343  typedef TypeList< Value , typename TypeListClean< Tail >::type > type ;
344 };
345 
346 //----------------------------------------------------------------------
351 template< typename T00 = TypeListEnd ,
352  typename T01 = TypeListEnd ,
353  typename T02 = TypeListEnd ,
354  typename T03 = TypeListEnd ,
355  typename T04 = TypeListEnd ,
356  typename T05 = TypeListEnd ,
357  typename T06 = TypeListEnd ,
358  typename T07 = TypeListEnd ,
359  typename T08 = TypeListEnd ,
360  typename T09 = TypeListEnd ,
361  typename T10 = TypeListEnd ,
362  typename T11 = TypeListEnd ,
363  typename T12 = TypeListEnd ,
364  typename T13 = TypeListEnd ,
365  typename T14 = TypeListEnd ,
366  typename T15 = TypeListEnd ,
367  typename T16 = TypeListEnd ,
368  typename T17 = TypeListEnd ,
369  typename T18 = TypeListEnd ,
370  typename T19 = TypeListEnd ,
371  typename T20 = TypeListEnd ,
372  typename T21 = TypeListEnd ,
373  typename T22 = TypeListEnd ,
374  typename T23 = TypeListEnd ,
375  typename T24 = TypeListEnd ,
376  typename T25 = TypeListEnd ,
377  typename T26 = TypeListEnd ,
378  typename T27 = TypeListEnd ,
379  typename T28 = TypeListEnd ,
380  typename T29 = TypeListEnd ,
381  typename T30 = TypeListEnd ,
382  typename T31 = TypeListEnd ,
383  typename T32 = TypeListEnd ,
384  typename T33 = TypeListEnd ,
385  typename T34 = TypeListEnd ,
386  typename T35 = TypeListEnd ,
387  typename T36 = TypeListEnd ,
388  typename T37 = TypeListEnd ,
389  typename T38 = TypeListEnd ,
390  typename T39 = TypeListEnd ,
391  typename T40 = TypeListEnd ,
392  typename T41 = TypeListEnd ,
393  typename T42 = TypeListEnd ,
394  typename T43 = TypeListEnd ,
395  typename T44 = TypeListEnd ,
396  typename T45 = TypeListEnd ,
397  typename T46 = TypeListEnd ,
398  typename T47 = TypeListEnd ,
399  typename T48 = TypeListEnd ,
400  typename T49 = TypeListEnd ,
401  typename T50 = TypeListEnd ,
402  typename T51 = TypeListEnd ,
403  typename T52 = TypeListEnd ,
404  typename T53 = TypeListEnd ,
405  typename T54 = TypeListEnd ,
406  typename T55 = TypeListEnd ,
407  typename T56 = TypeListEnd ,
408  typename T57 = TypeListEnd ,
409  typename T58 = TypeListEnd ,
410  typename T59 = TypeListEnd ,
411  typename T60 = TypeListEnd ,
412  typename T61 = TypeListEnd ,
413  typename T62 = TypeListEnd ,
414  typename T63 = TypeListEnd >
416 {
417 #ifndef DOXYGEN_COMPILE
418 private:
419  typedef TypeList< T00 ,
420  TypeList< T01 ,
421  TypeList< T02 ,
422  TypeList< T03 ,
423  TypeList< T04 ,
424  TypeList< T05 ,
425  TypeList< T06 ,
426  TypeList< T07 ,
427  TypeList< T08 ,
428  TypeList< T09 ,
429  TypeList< T10 ,
430  TypeList< T11 ,
431  TypeList< T12 ,
432  TypeList< T13 ,
433  TypeList< T14 ,
434  TypeList< T15 ,
435  TypeList< T16 ,
436  TypeList< T17 ,
437  TypeList< T18 ,
438  TypeList< T19 ,
439  TypeList< T20 ,
440  TypeList< T21 ,
441  TypeList< T22 ,
442  TypeList< T23 ,
443  TypeList< T24 ,
444  TypeList< T25 ,
445  TypeList< T26 ,
446  TypeList< T27 ,
447  TypeList< T28 ,
448  TypeList< T29 ,
449  TypeList< T30 ,
450  TypeList< T31 ,
451  TypeList< T32 ,
452  TypeList< T33 ,
453  TypeList< T34 ,
454  TypeList< T35 ,
455  TypeList< T36 ,
456  TypeList< T37 ,
457  TypeList< T38 ,
458  TypeList< T39 ,
459  TypeList< T40 ,
460  TypeList< T41 ,
461  TypeList< T42 ,
462  TypeList< T43 ,
463  TypeList< T44 ,
464  TypeList< T45 ,
465  TypeList< T46 ,
466  TypeList< T47 ,
467  TypeList< T48 ,
468  TypeList< T49 ,
469  TypeList< T50 ,
470  TypeList< T51 ,
471  TypeList< T52 ,
472  TypeList< T53 ,
473  TypeList< T54 ,
474  TypeList< T55 ,
475  TypeList< T56 ,
476  TypeList< T57 ,
477  TypeList< T58 ,
478  TypeList< T59 ,
479  TypeList< T60 ,
480  TypeList< T61 ,
481  TypeList< T62 ,
482  TypeList< T63 ,
483  TypeListEnd > > > > > > > > > > > > > > > >
484  > > > > > > > > > > > > > > > >
485  > > > > > > > > > > > > > > > >
486  > > > > > > > > > > > > > > > > dirty_type ;
487 #endif /* DOXYGEN_COMPILE */
488 public:
489 
492 
494  enum { length = TypeListLength<type>::value };
495 
497  enum { unique = TypeListUnique<type>::value };
498 };
499 
501 } // namespace shards
502 
503 #endif // Shards_TypeList_hpp
504 
Member typedef ... type ; is defined by appending T to the end of ListA .
Member enum { value = ... }; is the location within ListType of occurance I of type TestValue ...
Member typedef ... type ; is the first member of ListType .
TypeListClean< dirty_type >::type type
The constructed type list.
Member enum { value = ... }; is the length of the type list.
Member enum { value = ... }; is true if each member of ListType appears exactly once...
Member enum { value = ... }; is true if all members of ListA are not a member ListB ...
A link within a linked list of types.
Member enum { value = ... }; is true if TestValue is a member of ListType .
Member enum { value = ... }; is the number of occurances of TestValue within ListType ...
Member typedef ... type ; is defined by truncating ListType at the first occurance of TypeListEn...
Member typedef ... type ; is the last member of ListType .
Member typedef ... type ; is the type of the member of ListType at location ordinal if ordinal...
Member typedef ... type ; is defined by joining ListB to the end of ListA .
Member typedef ... type ; is a type list constructed from the template arguments.
Member enum { value = ... }; is true if T1 and T2 are the same type.
Member typedef ... type ; is defined by erasing member at ordinal from ListType ...