Sierra Toolkit Version of the Day
TypeList.hpp
00001 /*------------------------------------------------------------------------*/
00002 /*                 Copyright 2010 Sandia Corporation.                     */
00003 /*  Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive   */
00004 /*  license for use of this work by or on behalf of the U.S. Government.  */
00005 /*  Export of this program may require a license from the                 */
00006 /*  United States Government.                                             */
00007 /*------------------------------------------------------------------------*/
00008 
00009 
00010 #ifndef stk_util_util_TypeList_h
00011 #define stk_util_util_TypeList_h
00012 
00013 #include <stk_util/util/TypeUtil.hpp>
00014 #include <stk_util/util/SameType.hpp>
00015 
00016 namespace stk {
00017 
00028 //----------------------------------------------------------------------
00029 
00030 struct TypeListEnd {};
00031 
00040 template< typename Value , class Tail = TypeListEnd > struct TypeList {};
00041 
00042 //----------------------------------------------------------------------
00048 template< class ListType > struct TypeListLength {};
00049 
00050 template<>
00051 struct TypeListLength< TypeListEnd >
00052 { enum { value = 0 }; };
00053 
00054 template< typename Value , class Tail >
00055 struct TypeListLength< TypeList< Value , Tail > >
00056 { enum { value = 1 + TypeListLength< Tail >::value }; };
00057 
00058 //----------------------------------------------------------------------
00065 template< class ListType, unsigned ordinal > struct TypeListAt {};
00066 
00067 template< unsigned ordinal >
00068 struct TypeListAt< TypeListEnd , ordinal >
00069 { typedef TypeListEnd type ; };
00070 
00071 template< typename Value , class Tail >
00072 struct TypeListAt< TypeList< Value , Tail > , 0 >
00073 { typedef Value type ; };
00074 
00075 template< typename Value , class Tail , unsigned ordinal >
00076 struct TypeListAt< TypeList< Value , Tail > , ordinal >
00077 { typedef typename TypeListAt< Tail , ordinal - 1 >::type type ; };
00078 
00079 //----------------------------------------------------------------------
00087 template< class ListType , typename TestValue , unsigned ordinal = 0 >
00088 struct TypeListIndex {};
00089 
00090 template< typename TestValue , unsigned ordinal >
00091 struct TypeListIndex< TypeListEnd , TestValue , ordinal >
00092 {
00093   enum { value = -1 };
00094 };
00095 
00096 template< typename Value , class Tail , typename TestValue , unsigned ordinal >
00097 struct TypeListIndex< TypeList< Value , Tail > , TestValue , ordinal >
00098 {
00099 private:
00100   enum { match = stk::SameType< Value , TestValue >::value };
00101   enum { J = match && 0 < ordinal ? ordinal - 1 : ordinal };
00102   enum { N = TypeListIndex< Tail , TestValue , J >::value };
00103 public:
00104   enum { value = match && 0 == ordinal ? 0 : ( -1 == N ? -1 : N + 1 ) };
00105 };
00106 
00107 //----------------------------------------------------------------------
00114 template< class ListType , typename TestValue >
00115 struct TypeListCount {};
00116 
00117 template< typename TestValue >
00118 struct TypeListCount< TypeListEnd , TestValue >
00119 { enum { value = 0 }; };
00120 
00121 template< typename Value , class Tail , typename TestValue >
00122 struct TypeListCount< TypeList< Value , Tail > , TestValue >
00123 {
00124   enum { value = TypeListCount< Tail , TestValue >::value +
00125                  ( stk::SameType< Value , TestValue >::value ? 1 : 0 ) };
00126 };
00127 
00128 //----------------------------------------------------------------------
00134 template< class ListType , typename TestValue > struct TypeListMember {};
00135 
00136 template< typename TestValue >
00137 struct TypeListMember< TypeListEnd , TestValue >
00138 { enum { value = false }; };
00139 
00140 template< typename Value , class Tail , typename TestValue >
00141 struct TypeListMember< TypeList< Value , Tail > , TestValue >
00142 {
00143   enum { value = stk::SameType< Value , TestValue >::value ||
00144                  TypeListMember< Tail , TestValue >::value };
00145 };
00146 
00147 //----------------------------------------------------------------------
00153 template< class ListType > struct TypeListUnique {};
00154 
00155 template<>
00156 struct TypeListUnique< TypeListEnd >
00157 { enum { value = true }; };
00158 
00159 template< typename Value , class Tail >
00160 struct TypeListUnique< TypeList< Value , Tail > >
00161 {
00162   enum { value = ! TypeListMember< Tail , Value >::value &&
00163                  TypeListUnique< Tail >::value };
00164 };
00165 
00166 //----------------------------------------------------------------------
00173 template< class ListA , class ListB > struct TypeListDisjoint {};
00174 
00175 template< class ListB >
00176 struct TypeListDisjoint< TypeListEnd , ListB >
00177 { enum { value = true }; };
00178 
00179 template< typename Value , class Tail , class ListB >
00180 struct TypeListDisjoint< TypeList< Value , Tail > , ListB >
00181 {
00182   enum { value = ! TypeListMember< ListB , Value >::value &&
00183                  TypeListDisjoint< Tail , ListB >::value };
00184 };
00185 
00186 //----------------------------------------------------------------------
00192 template< class ListType > struct TypeListFirst {};
00193 
00194 template<>
00195 struct TypeListFirst< TypeListEnd >
00196 { typedef TypeListEnd type ; };
00197 
00198 template< typename Value , class Tail >
00199 struct TypeListFirst< TypeList< Value , Tail > >
00200 { typedef Value type ; };
00201 
00202 //----------------------------------------------------------------------
00208 template< class ListType > struct TypeListLast {};
00209 
00210 template<>
00211 struct TypeListLast< TypeListEnd >
00212 { typedef TypeListEnd type ; };
00213 
00214 template< typename Value >
00215 struct TypeListLast< TypeList< Value , TypeListEnd > >
00216 { typedef Value type ; };
00217 
00218 template< typename Value , class Tail >
00219 struct TypeListLast< TypeList< Value , Tail > >
00220 { typedef typename TypeListLast< Tail >::type type ; };
00221 
00222 //----------------------------------------------------------------------
00228 template< class ListA , typename T > struct TypeListAppend {};
00229 
00230 template<>
00231 struct TypeListAppend< TypeListEnd , TypeListEnd >
00232 { typedef TypeListEnd type ; };
00233 
00234 template< typename T >
00235 struct TypeListAppend< TypeListEnd , T >
00236 { typedef TypeList< T > type ; };
00237 
00238 template< typename Value , class Tail , typename T >
00239 struct TypeListAppend< TypeList< Value , Tail > , T >
00240 {
00241   typedef TypeList< Value , typename TypeListAppend< Tail , T >::type > type ;
00242 };
00243 
00244 //----------------------------------------------------------------------
00250 template< class ListA , class ListB > struct TypeListJoin {};
00251 
00252 template<>
00253 struct TypeListJoin< TypeListEnd , TypeListEnd >
00254 { typedef TypeListEnd type ; };
00255 
00256 template< typename Value , class Tail >
00257 struct TypeListJoin< TypeListEnd , TypeList< Value , Tail > >
00258 { typedef TypeList< Value , Tail > type ; };
00259 
00260 template< typename ValueA , class TailA , typename ValueB , class TailB >
00261 struct TypeListJoin< TypeList< ValueA , TailA > ,
00262                      TypeList< ValueB , TailB > >
00263 {
00264 private:
00265   typedef typename
00266     TypeListJoin< TailA , TypeList< ValueB , TailB > >::type Tail ;
00267 public:
00268   typedef TypeList< ValueA , Tail > type ;
00269 };
00270 
00271 //----------------------------------------------------------------------
00277 template< class ListType, unsigned ordinal > struct TypeListEraseAt {};
00278 
00279 template< typename Value , class Tail >
00280 struct TypeListEraseAt< TypeList< Value , Tail > , 0 >
00281 { typedef Tail type ; };
00282 
00283 template< typename Value , class Tail , unsigned ordinal >
00284 struct TypeListEraseAt< TypeList< Value , Tail > , ordinal >
00285 {
00286   typedef TypeList< Value ,
00287                     typename TypeListEraseAt<Tail,ordinal-1>::type > type ;
00288 };
00289 
00290 
00291 //----------------------------------------------------------------------
00298 template< class ListType > struct TypeListClean {};
00299 
00300 template<>
00301 struct TypeListClean< TypeListEnd >
00302 { typedef TypeListEnd type ; };
00303 
00304 template< class Tail >
00305 struct TypeListClean< TypeList< TypeListEnd , Tail > >
00306 { typedef TypeListEnd type ; };
00307 
00308 template< typename Value , class Tail >
00309 struct TypeListClean< TypeList< Value , Tail > >
00310 {
00311   typedef TypeList< Value , typename TypeListClean< Tail >::type > type ;
00312 };
00313 
00314 //----------------------------------------------------------------------
00320 template< typename T00 = TypeListEnd ,
00321           typename T01 = TypeListEnd ,
00322           typename T02 = TypeListEnd ,
00323           typename T03 = TypeListEnd ,
00324           typename T04 = TypeListEnd ,
00325           typename T05 = TypeListEnd ,
00326           typename T06 = TypeListEnd ,
00327           typename T07 = TypeListEnd ,
00328           typename T08 = TypeListEnd ,
00329           typename T09 = TypeListEnd ,
00330           typename T10 = TypeListEnd ,
00331           typename T11 = TypeListEnd ,
00332           typename T12 = TypeListEnd ,
00333           typename T13 = TypeListEnd ,
00334           typename T14 = TypeListEnd ,
00335           typename T15 = TypeListEnd ,
00336           typename T16 = TypeListEnd ,
00337           typename T17 = TypeListEnd ,
00338           typename T18 = TypeListEnd ,
00339           typename T19 = TypeListEnd ,
00340           typename T20 = TypeListEnd ,
00341           typename T21 = TypeListEnd ,
00342           typename T22 = TypeListEnd ,
00343           typename T23 = TypeListEnd ,
00344           typename T24 = TypeListEnd ,
00345           typename T25 = TypeListEnd ,
00346           typename T26 = TypeListEnd ,
00347           typename T27 = TypeListEnd ,
00348           typename T28 = TypeListEnd ,
00349           typename T29 = TypeListEnd ,
00350           typename T30 = TypeListEnd ,
00351           typename T31 = TypeListEnd ,
00352           typename T32 = TypeListEnd ,
00353           typename T33 = TypeListEnd ,
00354           typename T34 = TypeListEnd ,
00355           typename T35 = TypeListEnd ,
00356           typename T36 = TypeListEnd ,
00357           typename T37 = TypeListEnd ,
00358           typename T38 = TypeListEnd ,
00359           typename T39 = TypeListEnd ,
00360           typename T40 = TypeListEnd ,
00361           typename T41 = TypeListEnd ,
00362           typename T42 = TypeListEnd ,
00363           typename T43 = TypeListEnd ,
00364           typename T44 = TypeListEnd ,
00365           typename T45 = TypeListEnd ,
00366           typename T46 = TypeListEnd ,
00367           typename T47 = TypeListEnd ,
00368           typename T48 = TypeListEnd ,
00369           typename T49 = TypeListEnd ,
00370           typename T50 = TypeListEnd ,
00371           typename T51 = TypeListEnd ,
00372           typename T52 = TypeListEnd ,
00373           typename T53 = TypeListEnd ,
00374           typename T54 = TypeListEnd ,
00375           typename T55 = TypeListEnd ,
00376           typename T56 = TypeListEnd ,
00377           typename T57 = TypeListEnd ,
00378           typename T58 = TypeListEnd ,
00379           typename T59 = TypeListEnd ,
00380           typename T60 = TypeListEnd ,
00381           typename T61 = TypeListEnd ,
00382           typename T62 = TypeListEnd ,
00383           typename T63 = TypeListEnd >
00384 struct MakeTypeList
00385 {
00386 #ifndef DOXYGEN_COMPILE
00387 private:
00388   typedef  TypeList< T00 ,
00389            TypeList< T01 ,
00390            TypeList< T02 ,
00391            TypeList< T03 ,
00392            TypeList< T04 ,
00393            TypeList< T05 ,
00394            TypeList< T06 ,
00395            TypeList< T07 ,
00396            TypeList< T08 ,
00397            TypeList< T09 ,
00398            TypeList< T10 ,
00399            TypeList< T11 ,
00400            TypeList< T12 ,
00401            TypeList< T13 ,
00402            TypeList< T14 ,
00403            TypeList< T15 ,
00404            TypeList< T16 ,
00405            TypeList< T17 ,
00406            TypeList< T18 ,
00407            TypeList< T19 ,
00408            TypeList< T20 ,
00409            TypeList< T21 ,
00410            TypeList< T22 ,
00411            TypeList< T23 ,
00412            TypeList< T24 ,
00413            TypeList< T25 ,
00414            TypeList< T26 ,
00415            TypeList< T27 ,
00416            TypeList< T28 ,
00417            TypeList< T29 ,
00418            TypeList< T30 ,
00419            TypeList< T31 ,
00420            TypeList< T32 ,
00421            TypeList< T33 ,
00422            TypeList< T34 ,
00423            TypeList< T35 ,
00424            TypeList< T36 ,
00425            TypeList< T37 ,
00426            TypeList< T38 ,
00427            TypeList< T39 ,
00428            TypeList< T40 ,
00429            TypeList< T41 ,
00430            TypeList< T42 ,
00431            TypeList< T43 ,
00432            TypeList< T44 ,
00433            TypeList< T45 ,
00434            TypeList< T46 ,
00435            TypeList< T47 ,
00436            TypeList< T48 ,
00437            TypeList< T49 ,
00438            TypeList< T50 ,
00439            TypeList< T51 ,
00440            TypeList< T52 ,
00441            TypeList< T53 ,
00442            TypeList< T54 ,
00443            TypeList< T55 ,
00444            TypeList< T56 ,
00445            TypeList< T57 ,
00446            TypeList< T58 ,
00447            TypeList< T59 ,
00448            TypeList< T60 ,
00449            TypeList< T61 ,
00450            TypeList< T62 ,
00451            TypeList< T63 ,
00452            TypeListEnd > > > > > > > > > > > > > > > >
00453                        > > > > > > > > > > > > > > > >
00454                        > > > > > > > > > > > > > > > >
00455                        > > > > > > > > > > > > > > > > dirty_type ;
00456 #endif /* DOXYGEN_COMPILE */
00457 public:
00458 
00460   typedef typename TypeListClean< dirty_type >::type type ;
00461 
00463   enum { length = TypeListLength<type>::value };
00464 
00466   enum { unique = TypeListUnique<type>::value };
00467 };
00468 
00469 } // namespace stk
00470 
00471 namespace sierra {
00472 
00473 //----------------------------------------------------------------------
00474 
00478 template<typename ValueType, typename ListType>
00479 struct TypeList {
00481   typedef ValueType TypeListValue ;
00482 
00484   typedef ListType  TypeListTail ;
00485 };
00486 
00491 struct TypeListEnd {};
00492 
00493 //----------------------------------------------------------------------
00494 
00496 template< class ListType>
00497 struct TypeListLength /* { enum { value = <> }; } */ ;
00498 
00500 template< class ListType, typename ValueType, unsigned Ordinal = 0>
00501 struct TypeListIndex /* { enum { value = <> }; } */ ;
00502 
00504 template< class ListType, typename ValueType>
00505 struct TypeListCount /* { enum { value = <> }; } */ ;
00506 
00508 template< class ListType >
00509 struct TypeListLast /* { typedef <> type ; } */ ;
00510 
00512 template< class ListType, unsigned I>
00513 struct TypeListAt /* { typedef <> type ; typedef <> list_type ; } */ ;
00514 
00516 template< class ListType, typename ValueType>
00517 struct TypeListMember /* { typedef <> list_type ; } */ ;
00518 
00520 template< class ListType, unsigned I >
00521 struct TypeListEraseAt /* { typedef <> list_type ; } */ ;
00522 
00523 // /** Erase type from TypeList at I */
00524 // template< class ListType, int I >
00525 // struct TypeListErase /* { typedef <> list_type ; } */ ;
00526 
00528 template< class ListType >
00529 struct TypeListUnique /* { enum { value = <> }; } */ ;
00530 
00532 template< class SuperList , class SubList >
00533 struct TypeListContains /* { enum { value = <> }; } */ ;
00534 
00536 template< class ListA , class ListB >
00537 struct TypeListDisjoint /* { enum { value = <> }; } */ ;
00538 
00540 template<class ListType>
00541 struct TypeListClean /* { typedef <> list_type ; } */ ;
00542 
00546 template< typename T0 = TypeListEnd ,
00547     typename T1 = TypeListEnd ,
00548     typename T2 = TypeListEnd ,
00549     typename T3 = TypeListEnd ,
00550     typename T4 = TypeListEnd ,
00551     typename T5 = TypeListEnd ,
00552     typename T6 = TypeListEnd ,
00553     typename T7 = TypeListEnd ,
00554     typename T8 = TypeListEnd ,
00555     typename T9 = TypeListEnd ,
00556     typename T10 = TypeListEnd ,
00557     typename T11 = TypeListEnd ,
00558     typename T12 = TypeListEnd ,
00559     typename T13 = TypeListEnd ,
00560     typename T14 = TypeListEnd ,
00561     typename T15 = TypeListEnd ,
00562     typename T16 = TypeListEnd ,
00563     typename T17 = TypeListEnd ,
00564     typename T18 = TypeListEnd ,
00565     typename T19 = TypeListEnd ,
00566     typename T20 = TypeListEnd ,
00567     typename T21 = TypeListEnd ,
00568     typename T22 = TypeListEnd ,
00569     typename T23 = TypeListEnd ,
00570     typename T24 = TypeListEnd ,
00571     typename T25 = TypeListEnd ,
00572     typename T26 = TypeListEnd ,
00573     typename T27 = TypeListEnd ,
00574     typename T28 = TypeListEnd ,
00575     typename T29 = TypeListEnd ,
00576     typename T30 = TypeListEnd ,
00577     typename T31 = TypeListEnd >
00578 struct MakeTypeList
00579 /* { typedef <> type ; enum { length = <> , unique = <> }; } */ ;
00580 
00581 //----------------------------------------------------------------------
00582 //----------------------------------------------------------------------
00583 // Clean: End -> End
00584 // Clean: <End,  Tail> -> End
00585 // Clean: <Value,Tail> -> < Value , Clean<Tail> >
00586 
00587 template<>
00588 struct TypeListClean<TypeListEnd> {
00589   typedef TypeListEnd list_type ;
00590 };
00591 
00592 template<typename Tail>
00593 struct TypeListClean< TypeList< TypeListEnd , Tail > > {
00594   typedef TypeListEnd list_type ;
00595 };
00596 
00597 template<class ListType>
00598 struct TypeListClean {
00599 private:
00600   typedef typename ListType::TypeListValue                 ValueType ;
00601   typedef typename ListType::TypeListTail                  InputTailType ;
00602   typedef typename TypeListClean<InputTailType>::list_type TailType ;
00603 public:
00604   typedef TypeList< ValueType , TailType > list_type ;
00605 };
00606 
00607 //----------
00608 // Length: End          -> 0
00609 // Length: <End,  Tail> -> 0
00610 // Length: <Value,Tail> -> 1 + Length<Tail>
00611 
00612 template<> struct TypeListLength<TypeListEnd>
00613 { enum { value = 0 }; };
00614 
00615 template<class ListType>
00616 struct TypeListLength< TypeList<TypeListEnd,ListType> >
00617 { enum { value = 0 }; };
00618 
00619 template<class ListType>
00620 struct TypeListLength
00621 {
00622 private: typedef typename ListType::TypeListTail TailType ;
00623 public:  enum { value = 1 + TypeListLength<TailType>::value };
00624 };
00625 
00626 //----------
00627 // Index:  < End ,                  ValueType >  ->  -1
00628 // Index:  < List ,                 End >        ->  -1
00629 // Index:  < < End ,       Tail > , ValueType >  ->  -1
00630 // Index:  < < ValueType , Tail > , ValueType >  ->   0
00631 // Index:  < < OtherType , Tail > , ValueType >  ->
00632 //         ( I = Index<List::Tail,ValueType> , I == -1 ? -1 : I + 1 )
00633 
00634 template<typename ValueType, unsigned Ordinal>
00635 struct TypeListIndex< TypeListEnd , ValueType , Ordinal> {
00636   enum { value = -1 };
00637   typedef TypeListEnd tail_type ;
00638 };
00639 
00640 template<class ListType, unsigned Ordinal>
00641 struct TypeListIndex< ListType , TypeListEnd , Ordinal > {
00642   enum { value = -1 };
00643   typedef TypeListEnd tail_type ;
00644 };
00645 
00646 template<class Tail, typename ValueType, unsigned Ordinal >
00647 struct TypeListIndex< TypeList<TypeListEnd,Tail> , ValueType, Ordinal >
00648 {
00649   enum { value = -1 };
00650   typedef TypeListEnd tail_type ;
00651 };
00652 
00653 template<typename ValueType, class Tail>
00654 struct TypeListIndex< TypeList<ValueType,Tail> , ValueType , 0 >
00655 {
00656   enum { value = 0 };
00657   typedef Tail tail_type ;
00658 };
00659 
00660 // Condition: ValueType == ListType::TypeListValue && Ordinal matches
00661 
00662 template<class ListType, typename ValueType, unsigned Ordinal>
00663 struct TypeListIndex
00664 {
00665 private:
00666   enum { same = stk::SameType<ValueType,typename ListType::TypeListValue>::value };
00667   enum { ord = Ordinal == 0 ? 0 : ( same ? Ordinal - 1 : Ordinal ) };
00668   typedef typename ListType::TypeListTail TailType ;
00669   typedef TypeListIndex< TailType , ValueType , ord > type_list_index ;
00670   enum { temp = type_list_index::value };
00671 public:
00672   enum { value = temp == -1 ? -1 : 1 + temp };
00673   typedef typename type_list_index::tail_type tail_type ;
00674 };
00675 
00676 //----------
00677 // Count :  < End , ValueType >  ->  0
00678 // Count :  < List , End >       ->  0
00679 // Count :  < < End ,       Tail > , ValueType >  ->  0
00680 // Count :  < < ValueType , Tail > , ValueType >  ->  Count<Tail,ValueType> + 1
00681 // Count :  < < OtherType , Tail > , ValueType >  ->  Count<Tail,ValueType>
00682 
00683 template<typename ValueType>
00684 struct TypeListCount< TypeListEnd , ValueType > { enum { value = 0 }; };
00685 
00686 template<class ListType>
00687 struct TypeListCount< ListType , TypeListEnd > { enum { value = 0 }; };
00688 
00689 template<class Tail, typename ValueType>
00690 struct TypeListCount< TypeList<TypeListEnd,Tail>,ValueType>
00691 { enum { value = 0 }; };
00692 
00693 template<typename ValueType, class Tail>
00694 struct TypeListCount< TypeList<ValueType,Tail> , ValueType>
00695 { enum { value = 1 + TypeListCount< Tail , ValueType >::value }; };
00696 
00697 template<class ListType, typename ValueType>
00698 struct TypeListCount
00699 {
00700 private: typedef typename ListType::TypeListTail TailType ;
00701 public:  enum { value = TypeListCount< TailType , ValueType >::value };
00702 };
00703 
00704 //----------
00705 // At :  < End ,                  0 >  ->  { End , End }
00706 // At :  < End ,                  I >  ->  { End , End }
00707 // At :  < < End ,       Tail > , I >  ->  { End , End }
00708 // At :  < < ValueType , Tail > , 0 >  ->  { ValueType , < ValueType , Tail > }
00709 // At :  < < ValueType , Tail > , I >  ->  At< Tail , I - 1 >
00710 
00711 template<>
00712 struct TypeListAt< TypeListEnd, 0>
00713 {
00714   typedef TypeListEnd type ;
00715   typedef TypeListEnd list_type ;
00716 };
00717 
00718 template<unsigned I>
00719 struct TypeListAt< TypeListEnd, I>
00720 {
00721   typedef TypeListEnd type ;
00722   typedef TypeListEnd list_type ;
00723 };
00724 
00725 template< class ListType >
00726 struct TypeListAt< ListType , 0 >
00727 {
00728 private:
00729   typedef typename ListType::TypeListTail Tail ;
00730 public:
00731   typedef typename ListType::TypeListValue type ;
00732   typedef TypeList< type , Tail >          list_type ;
00733 };
00734 
00735 template<class Tail, unsigned I>
00736 struct TypeListAt< TypeList<TypeListEnd,Tail>, I>
00737 {
00738   typedef TypeListEnd type ;
00739   typedef TypeListEnd list_type ;
00740 };
00741 
00742 template<class ListType, unsigned I>
00743 struct TypeListAt
00744 {
00745 private:
00746   typedef typename ListType::TypeListTail Tail ;
00747   typedef TypeListAt<Tail,I-1>            AtType ;
00748 public:
00749   typedef typename AtType::type      type ;
00750   typedef typename AtType::list_type list_type ;
00751 };
00752 
00753 //----------
00754 // Last : End -> End
00755 // Last : < ValueType , End >             ->  ValueType
00756 // Last : < ValueType , < End , Tail > >  ->  ValueType
00757 // Last : < ValueType , Tail >            ->  Last< Tail >
00758 
00759 template<>
00760 struct TypeListLast< TypeListEnd >
00761 { typedef TypeListEnd type ; };
00762 
00763 template<class ValueType>
00764 struct TypeListLast< TypeList<ValueType,TypeListEnd> >
00765 { typedef ValueType type ; };
00766 
00767 template<class ValueType,class Tail>
00768 struct TypeListLast< TypeList<ValueType,TypeList<TypeListEnd,Tail> > >
00769 { typedef ValueType type ; };
00770 
00771 template<class ValueType, class Tail>
00772 struct TypeListLast< TypeList<ValueType,Tail> >
00773 { typedef typename TypeListLast<Tail>::type type ; };
00774 
00775 //----------
00776 // Member :
00777 // Member :
00778 // Member :
00779 //
00780 
00781 template< typename ValueType >
00782 struct TypeListMember< TypeListEnd , ValueType >
00783 { typedef TypeListEnd list_type ; };
00784 
00785 template< class Tail , typename ValueType >
00786 struct TypeListMember< TypeList<TypeListEnd,Tail> , ValueType >
00787 { typedef TypeListEnd list_type ; };
00788 
00789 template< typename ValueType , class ListType>
00790 struct TypeListMember< TypeList<ValueType,ListType> , ValueType >
00791 { typedef TypeList<ValueType,ListType> list_type ; };
00792 
00793 template< class ListType, typename ValueType>
00794 struct TypeListMember
00795 {
00796   private: typedef typename ListType::TypeListTail Tail ;
00797   public:  typedef typename TypeListMember<Tail,ValueType>::list_type list_type;
00798 };
00799 
00800 // //----------
00801 // // Erase :
00802 // // Erase :
00803 // // Erase :
00804 // //
00805 
00806 // template< class ValueType>
00807 // struct TypeListErase<TypeListEnd, ValueType>
00808 // { typedef TypeListEnd list_type ; };
00809 
00810 // template< class ValueType, class Tail>
00811 // struct TypeListErase< TypeList<ValueType, Tail> , ValueType >
00812 // { typedef Tail list_type ; };
00813 
00814 // template< class ListType, class ValueType>
00815 // struct TypeListErase< TypeList<Head, Tail>, ValueType>
00816 // {
00817 // private: typedef typename ListType::TypeListTail Tail ;
00818 // public:  typedef TypeList<Head, typename TypeListErase<Tail, ValueType>::list_type> list_type;
00819 // };
00820 
00821 //----------
00822 // EraseAt :  < End ,                  0 >  ->  { End , End }
00823 // EraseAt :  < End ,                  I >  ->  { End , End }
00824 // EraseAt :  < < End ,       Tail > , I >  ->  { End , End }
00825 // EraseAt :  < < ListType ,           0 >  ->  { TypeList < ValueType , Tail > }
00826 // EraseAt :  < < ListType , Tail > ,  I >  ->  { EraseAt< Tail , I - 1 > }
00827 
00828 template<>
00829 struct TypeListEraseAt< TypeListEnd, 0>
00830 {
00831   typedef TypeListEnd       list_type ;
00832 };
00833 
00834 template<unsigned I>
00835 struct TypeListEraseAt< TypeListEnd, I>
00836 {
00837   typedef TypeListEnd       list_type ;
00838 };
00839 
00840 template<class Tail, unsigned I>
00841 struct TypeListEraseAt< TypeList<TypeListEnd,Tail>, I>
00842 {
00843   typedef TypeListEnd       list_type ;
00844 };
00845 
00846 template< class ListType >
00847 struct TypeListEraseAt< ListType , 0 >
00848 {
00849 private:
00850   typedef typename ListType::TypeListTail Tail ;
00851 public:
00852   typedef Tail          list_type ;
00853 };
00854 
00855 template<class ListType, unsigned I>
00856 struct TypeListEraseAt
00857 {
00858 private:
00859   typedef typename ListType::TypeListTail Tail ;
00860   typedef TypeListEraseAt<Tail, I - 1>    EraseAtType ;
00861 public:
00862   typedef TypeList<typename ListType::TypeListValue, typename EraseAtType::list_type> list_type ;
00863 };
00864 
00865 //----------
00866 // Unique :  End  ->  true
00867 // Unique :  < End , Tail >  -> true
00868 // Unique :  < ValueType , Tail >  ->
00869 //           Index<Tail,ValueType> == -1 && Unique<Tail>
00870 
00871 template<>
00872 struct TypeListUnique<TypeListEnd> { enum { value = true }; };
00873 
00874 template<class Tail>
00875 struct TypeListUnique< TypeList<TypeListEnd,Tail> >
00876 { enum { value = true }; };
00877 
00878 template< class ListType >
00879 struct TypeListUnique
00880 {
00881 private:
00882   typedef typename ListType::TypeListValue ValueType ;
00883   typedef typename ListType::TypeListTail  TailType ;
00884 public:
00885   // This ValueType does not appear in the remainder of the TypeList and
00886   // the remainder of the TypeList is also unique.
00887   enum { value = ( TypeListIndex<TailType,ValueType>::value == -1 ) &&
00888        TypeListUnique<TailType>::value };
00889 };
00890 
00891 //----------
00892 // Contains : < SuperList , End >  -> true
00893 // Contains : < SuperList , < End , Tail > >  -> true
00894 // Contains : < SuperList , SubList >  ->
00895 //            Index<   SuperList,SubList::Value> != -1 &&
00896 //            Contains<SuperList,SubList::Tail>
00897 
00898 template<class SuperList>
00899 struct TypeListContains<SuperList,TypeListEnd>
00900 { enum { value = true }; };
00901 
00902 template<class SuperList,typename Tail>
00903 struct TypeListContains<SuperList,TypeList<TypeListEnd,Tail> >
00904 { enum { value = true }; };
00905 
00906 template<class SuperList, class SubList >
00907 struct TypeListContains
00908 {
00909 private:
00910   typedef typename SubList::TypeListValue ValueType ;
00911   typedef typename SubList::TypeListTail  TailType ;
00912 public:
00913   // The SuperList contains this ValueType and the remainder of the SubList
00914   enum { value = ( TypeListIndex<SuperList,ValueType>::value != -1 ) &&
00915        TypeListContains<SuperList,TailType>::value };
00916 };
00917 
00918 //----------
00919 // Disjoint : < ListA , End >  ->  true
00920 // Disjoint : < ListA , < End , Tail > >  ->  true
00921 // Disjoint : < ListA , ListB >  ->
00922 //            Index<   ListA,ListB::Value> == -1 &&
00923 //            Disjoint<ListA,ListB::Tail>
00924 
00925 template<class SuperList>
00926 struct TypeListDisjoint<SuperList,TypeListEnd>
00927 { enum { value = true }; };
00928 
00929 template<class SuperList,typename Tail>
00930 struct TypeListDisjoint<SuperList,TypeList<TypeListEnd,Tail> >
00931 { enum { value = true }; };
00932 
00933 template<class ListA, class ListB>
00934 struct TypeListDisjoint
00935 {
00936 private:
00937   typedef typename ListB::TypeListValue ValueType ;
00938   typedef typename ListB::TypeListTail  TailType ;
00939 public:
00940   // ListA does not contain this ValueType and does not contain the remainder
00941   enum { value = ( TypeListIndex<ListA,ValueType>::value == -1 ) &&
00942        TypeListDisjoint<ListA,TailType>::value };
00943 };
00944 
00945 //----------------------------------------------------------------------
00946 
00947 template< typename T1 ,
00948     typename T2 ,
00949     typename T3 ,
00950     typename T4 ,
00951     typename T5 ,
00952     typename T6 ,
00953     typename T7 ,
00954     typename T8 ,
00955     typename T9 ,
00956     typename T10 ,
00957     typename T11 ,
00958     typename T12 ,
00959     typename T13 ,
00960     typename T14 ,
00961     typename T15 ,
00962     typename T16 ,
00963     typename T17 ,
00964     typename T18 ,
00965     typename T19 ,
00966     typename T20 ,
00967     typename T21 ,
00968     typename T22 ,
00969     typename T23 ,
00970     typename T24 ,
00971     typename T25 ,
00972     typename T26 ,
00973     typename T27 ,
00974     typename T28 ,
00975     typename T29 ,
00976     typename T30 ,
00977     typename T31 >
00978 struct MakeTypeList<TypeListEnd,
00979         T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,
00980         T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,
00981         T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31> {
00982   typedef TypeListEnd type ;
00983   enum { length = 0 };
00984   enum { unique = true };
00985 };
00986 
00987 template< typename T0 ,
00988     typename T1 ,
00989     typename T2 ,
00990     typename T3 ,
00991     typename T4 ,
00992     typename T5 ,
00993     typename T6 ,
00994     typename T7 ,
00995     typename T8 ,
00996     typename T9 ,
00997     typename T10 ,
00998     typename T11 ,
00999     typename T12 ,
01000     typename T13 ,
01001     typename T14 ,
01002     typename T15 ,
01003     typename T16 ,
01004     typename T17 ,
01005     typename T18 ,
01006     typename T19 ,
01007     typename T20 ,
01008     typename T21 ,
01009     typename T22 ,
01010     typename T23 ,
01011     typename T24 ,
01012     typename T25 ,
01013     typename T26 ,
01014     typename T27 ,
01015     typename T28 ,
01016     typename T29 ,
01017     typename T30 ,
01018     typename T31 >
01019 struct MakeTypeList {
01020   typedef typename TypeListClean<
01021     TypeList< T0 ,
01022     TypeList< T1,
01023     TypeList< T2 ,
01024     TypeList< T3 ,
01025     TypeList< T4 ,
01026     TypeList< T5 ,
01027     TypeList< T6 ,
01028     TypeList< T7 ,
01029     TypeList< T8 ,
01030     TypeList< T9 ,
01031     TypeList< T10 ,
01032     TypeList< T11 ,
01033     TypeList< T12 ,
01034     TypeList< T13 ,
01035     TypeList< T14 ,
01036     TypeList< T15 ,
01037     TypeList< T16 ,
01038     TypeList< T17 ,
01039     TypeList< T18 ,
01040     TypeList< T19 ,
01041     TypeList< T20 ,
01042     TypeList< T21 ,
01043     TypeList< T22 ,
01044     TypeList< T23 ,
01045     TypeList< T24 ,
01046     TypeList< T25 ,
01047     TypeList< T26 ,
01048     TypeList< T27 ,
01049     TypeList< T28 ,
01050     TypeList< T29 ,
01051     TypeList< T30 ,
01052     TypeList< T31 ,
01053     TypeListEnd > > > > > > > > > > > > > > > >
01054           > > > > > > > > > > > > > > > >
01055   >::list_type type ;
01056   enum { length = TypeListLength<type>::value };
01057   enum { unique = TypeListUnique<type>::value };
01058 };
01059 
01060 } // namespace sierra
01061 
01062 #endif // stk_util_util_TypeList_h
01063 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines