All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TypeList.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_UTIL_TYPELIST_H_
36 #define _BLAZE_UTIL_TYPELIST_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/util/NullType.h>
44 #include <blaze/util/Types.h>
45 
46 
47 namespace blaze {
48 
49 //=================================================================================================
50 //
51 // CLASS TYPELIST
52 //
53 //=================================================================================================
54 
55 //*************************************************************************************************
108 template< typename H // Head of the type list
109  , typename T > // Tail of the type list
110 struct TypeList
111 {
112  //**Type definitions****************************************************************************
113  typedef H Head;
114  typedef T Tail;
115  //**********************************************************************************************
116 };
117 //*************************************************************************************************
118 
119 
120 
121 
122 //=================================================================================================
123 //
124 // TYPE LIST GENERATION MACROS
125 //
126 //=================================================================================================
127 
128 //*************************************************************************************************
143 #define BLAZE_TYPELIST_1( T1 ) \
144  TypeList< T1, NullType >
145 //*************************************************************************************************
146 
147 
148 //*************************************************************************************************
164 #define BLAZE_TYPELIST_2( T1, T2 ) \
165  TypeList< T1, BLAZE_TYPELIST_1( T2 ) >
166 //*************************************************************************************************
167 
168 
169 //*************************************************************************************************
185 #define BLAZE_TYPELIST_3( T1, T2, T3 ) \
186  TypeList< T1, BLAZE_TYPELIST_2( T2, T3 ) >
187 //*************************************************************************************************
188 
189 
190 //*************************************************************************************************
206 #define BLAZE_TYPELIST_4( T1, T2, T3, T4 ) \
207  TypeList< T1, BLAZE_TYPELIST_3( T2, T3, T4 ) >
208 //*************************************************************************************************
209 
210 
211 //*************************************************************************************************
227 #define BLAZE_TYPELIST_5( T1, T2, T3, T4, T5 ) \
228  TypeList< T1, BLAZE_TYPELIST_4( T2, T3, T4, T5 ) >
229 //*************************************************************************************************
230 
231 
232 //*************************************************************************************************
248 #define BLAZE_TYPELIST_6( T1, T2, T3, T4, T5, T6 ) \
249  TypeList< T1, BLAZE_TYPELIST_5( T2, T3, T4, T5, T6 ) >
250 //*************************************************************************************************
251 
252 
253 //*************************************************************************************************
269 #define BLAZE_TYPELIST_7( T1, T2, T3, T4, T5, T6, T7 ) \
270  TypeList< T1, BLAZE_TYPELIST_6( T2, T3, T4, T5, T6, T7 ) >
271 //*************************************************************************************************
272 
273 
274 //*************************************************************************************************
290 #define BLAZE_TYPELIST_8( T1, T2, T3, T4, T5, T6, T7, T8 ) \
291  TypeList< T1, BLAZE_TYPELIST_7( T2, T3, T4, T5, T6, T7, T8 ) >
292 //*************************************************************************************************
293 
294 
295 //*************************************************************************************************
311 #define BLAZE_TYPELIST_9( T1, T2, T3, T4, T5, T6, T7, T8, T9 ) \
312  TypeList< T1, BLAZE_TYPELIST_8( T2, T3, T4, T5, T6, T7, T8, T9 ) >
313 //*************************************************************************************************
314 
315 
316 //*************************************************************************************************
333 #define BLAZE_TYPELIST_10( T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 ) \
334  TypeList< T1, BLAZE_TYPELIST_9( T2, T3, T4, T5, T6, T7, T8, T9, T10 ) >
335 //*************************************************************************************************
336 
337 
338 
339 
340 //=================================================================================================
341 //
342 // LENGTH OF A TYPE LIST
343 //
344 //=================================================================================================
345 
346 //*************************************************************************************************
362 template< typename TList > // Type of the type list
363 struct Length;
364 //*************************************************************************************************
365 
366 
367 //*************************************************************************************************
372 template<>
373 struct Length< NullType >
374 {
375  //**Member enumeration**************************************************************************
376  enum { value = 0 };
377  //**********************************************************************************************
378 };
380 //*************************************************************************************************
381 
382 
383 //*************************************************************************************************
388 template< typename Head // Type of the head of the type list
389  , typename Tail > // Type of the tail of the type list
390 struct Length< TypeList<Head,Tail> >
391 {
392  //**Member enumeration**************************************************************************
393  enum { value = 1 + Length<Tail>::value };
394  //**********************************************************************************************
395 };
397 //*************************************************************************************************
398 
399 
400 
401 
402 //=================================================================================================
403 //
404 // INDEXED ACCESS
405 //
406 //=================================================================================================
407 
408 //*************************************************************************************************
426 template< typename TList // Type of the type list
427  , size_t Index > // Type list access index
428 struct TypeAt;
429 //*************************************************************************************************
430 
431 
432 //*************************************************************************************************
437 template< typename Head // Type of the head of the type list
438  , typename Tail > // Type of the tail of the type list
439 struct TypeAt< TypeList<Head,Tail>, 0 >
440 {
441  //**Member enumeration**************************************************************************
442  typedef Head Result;
443  //**********************************************************************************************
444 };
446 //*************************************************************************************************
447 
448 
449 //*************************************************************************************************
454 template< typename Head // Type of the head of the type list
455  , typename Tail // Type of the tail of the type list
456  , size_t Index > // Type list access index
457 struct TypeAt< TypeList<Head,Tail>, Index >
458 {
459  //**Member enumeration**************************************************************************
460  typedef typename TypeAt< Tail, Index-1 >::Result Result;
461  //**********************************************************************************************
462 };
464 //*************************************************************************************************
465 
466 
467 
468 
469 //=================================================================================================
470 //
471 // TYPE LIST SEARCH
472 //
473 //=================================================================================================
474 
475 //*************************************************************************************************
496 template< typename TList // Type of the type list
497  , typename Type > // The search type
498 struct Contains;
499 //*************************************************************************************************
500 
501 
502 //*************************************************************************************************
507 template< typename Type > // The search type
508 struct Contains< NullType, Type >
509 {
510  //**Member enumeration**************************************************************************
511  enum { value = 0 };
512  //**********************************************************************************************
513 };
515 //*************************************************************************************************
516 
517 
518 //*************************************************************************************************
523 template< typename Tail // Type of the tail of the type list
524  , typename Type > // The search type
525 struct Contains< TypeList<Type,Tail>, Type >
526 {
527  //**Member enumeration**************************************************************************
528  enum { value = 1 };
529  //**********************************************************************************************
530 };
532 //*************************************************************************************************
533 
534 
535 //*************************************************************************************************
540 template< typename Head // Type of the head of the type list
541  , typename Tail // Type of the tail of the type list
542  , typename Type > // The search type
543 struct Contains< TypeList<Head,Tail>, Type >
544 {
545  //**Member enumeration**************************************************************************
546  enum { value = Contains<Tail,Type>::value };
547  //**********************************************************************************************
548 };
550 //*************************************************************************************************
551 
552 
553 //*************************************************************************************************
585 template< typename TList // Type of the type list
586  , typename Type > // The search type
588 //*************************************************************************************************
589 
590 
591 //*************************************************************************************************
596 template< typename Type > // The search type
597 struct ContainsRelated< NullType, Type >
598 {
599  //**Member enumeration**************************************************************************
600  enum { value = 0 };
601  //**********************************************************************************************
602 };
604 //*************************************************************************************************
605 
606 
607 //*************************************************************************************************
612 template< typename Head // Type of the head of the type list
613  , typename Tail // Type of the tail of the type list
614  , typename Type > // The search type
615 struct ContainsRelated< TypeList<Head,Tail>, Type >
616 {
617  private:
618  //**********************************************************************************************
619  class No {};
620  class Yes { No no[2]; };
621  //**********************************************************************************************
622 
623  //**********************************************************************************************
624  static Yes test( Head );
625  static No test( ... );
626  static Type createType();
627  //**********************************************************************************************
628 
629  //**Member enumeration**************************************************************************
630  enum { tmp = sizeof( test( createType() ) ) == sizeof( Yes ) ? 1 : 0 };
631  //**********************************************************************************************
632 
633  public:
634  //**Member enumeration**************************************************************************
635  enum { value = tmp == 1 ? 1 : ( ContainsRelated<Tail,Type>::value ) };
636  //**********************************************************************************************
637 };
639 //*************************************************************************************************
640 
641 
642 //*************************************************************************************************
661 template< typename TList // Type of the type list
662  , typename Type > // The search type
663 struct IndexOf;
664 //*************************************************************************************************
665 
666 
667 //*************************************************************************************************
672 template< typename Type > // The search type
673 struct IndexOf< NullType, Type >
674 {
675  //**Member enumeration**************************************************************************
676  enum { value = -1 };
677  //**********************************************************************************************
678 };
680 //*************************************************************************************************
681 
682 
683 //*************************************************************************************************
688 template< typename Tail // Type of the tail of the type list
689  , typename Type > // The search type
690 struct IndexOf< TypeList<Type,Tail>, Type >
691 {
692  //**Member enumeration**************************************************************************
693  enum { value = 0 };
694  //**********************************************************************************************
695 };
697 //*************************************************************************************************
698 
699 
700 //*************************************************************************************************
705 template< typename Head // Type of the head of the type list
706  , typename Tail // Type of the tail of the type list
707  , typename Type > // The search type
708 struct IndexOf< TypeList<Head,Tail>, Type >
709 {
710  private:
711  //**Member enumeration**************************************************************************
712  enum { tmp = IndexOf<Tail,Type>::value };
713  //**********************************************************************************************
714 
715  public:
716  //**Member enumeration**************************************************************************
717  enum { value = tmp == -1 ? -1 : 1 + tmp };
718  //**********************************************************************************************
719 };
721 //*************************************************************************************************
722 
723 
724 
725 
726 //=================================================================================================
727 //
728 // APPENDING TO TYPE LISTS
729 //
730 //=================================================================================================
731 
732 //*************************************************************************************************
747 template< typename TList // Type of the type list
748  , typename Type > // The type to be appended to the type list
749 struct Append;
750 //*************************************************************************************************
751 
752 
753 //*************************************************************************************************
758 template<>
759 struct Append< NullType, NullType >
760 {
761  //**Type definitions****************************************************************************
762  typedef NullType Result;
763  //**********************************************************************************************
764 };
766 //*************************************************************************************************
767 
768 
769 //*************************************************************************************************
774 template< typename Type > // The type to be appended to the type list
775 struct Append< NullType, Type >
776 {
777  //**Type definitions****************************************************************************
778  typedef BLAZE_TYPELIST_1( Type ) Result;
779  //**********************************************************************************************
780 };
782 //*************************************************************************************************
783 
784 
785 //*************************************************************************************************
790 template< typename Head // Type of the head of the type list
791  , typename Tail > // Type of the tail of the type list
792 struct Append< NullType, TypeList<Head,Tail> >
793 {
794  //**Type definitions****************************************************************************
795  typedef TypeList<Head,Tail> Result;
796  //**********************************************************************************************
797 };
799 //*************************************************************************************************
800 
801 
802 //*************************************************************************************************
807 template< typename Head // Type of the head of the type list
808  , typename Tail // Type of the tail of the type list
809  , typename Type > // The type to be appended to the type list
810 struct Append< TypeList<Head,Tail>, Type >
811 {
812  //**Type definitions****************************************************************************
813  typedef TypeList< Head, typename Append<Tail,Type>::Result > Result;
814  //**********************************************************************************************
815 };
817 //*************************************************************************************************
818 
819 } // namespace blaze
820 
821 #endif
Utility type for generic codes.
Appending a type to a type list.The Append class can be used to append the data type Type to a type l...
Definition: TypeList.h:749
#define BLAZE_TYPELIST_1(T1)
Type list generation macro.This macro creates a type list only consisting of the type T1...
Definition: TypeList.h:143
Implementation of a type list.The TypeList class is an implementation of a type list according to the...
Definition: TypeList.h:110
T Tail
Type of the tail of the type list.
Definition: TypeList.h:114
Calculating the length of a type list.The Length class can be used to obtain the length of a type lis...
Definition: TypeList.h:363
Searching a type list.The ContainsRelated class can be used to search the type list for a type relate...
Definition: TypeList.h:587
Indexing a type list.The TypeAt class can be used to access a type list at a specified position to qu...
Definition: TypeList.h:428
Utility type for generic codes.The NullType class represents an invalid or terminating data type for ...
Definition: NullType.h:54
Header file for basic type definitions.
Searching a type list.The Contains class can be used to search the type list for a particular type Ty...
Definition: TypeList.h:498
H Head
Type of the head of the type list.
Definition: TypeList.h:113
Searching a type list.The IndexOf class can be used to search the type list for a particular type Typ...
Definition: TypeList.h:663