All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TypeList.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_UTIL_TYPELIST_H_
23 #define _BLAZE_UTIL_TYPELIST_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
30 #include <blaze/util/NullType.h>
31 #include <blaze/util/Types.h>
32 
33 
34 namespace blaze {
35 
36 //=================================================================================================
37 //
38 // CLASS TYPELIST
39 //
40 //=================================================================================================
41 
42 //*************************************************************************************************
95 template< typename H // Head of the type list
96  , typename T > // Tail of the type list
97 struct TypeList
98 {
99  //**Type definitions****************************************************************************
100  typedef H Head;
101  typedef T Tail;
102  //**********************************************************************************************
103 };
104 //*************************************************************************************************
105 
106 
107 
108 
109 //=================================================================================================
110 //
111 // TYPE LIST GENERATION MACROS
112 //
113 //=================================================================================================
114 
115 //*************************************************************************************************
130 #define BLAZE_TYPELIST_1( T1 ) \
131  TypeList< T1, NullType >
132 //*************************************************************************************************
133 
134 
135 //*************************************************************************************************
151 #define BLAZE_TYPELIST_2( T1, T2 ) \
152  TypeList< T1, BLAZE_TYPELIST_1( T2 ) >
153 //*************************************************************************************************
154 
155 
156 //*************************************************************************************************
172 #define BLAZE_TYPELIST_3( T1, T2, T3 ) \
173  TypeList< T1, BLAZE_TYPELIST_2( T2, T3 ) >
174 //*************************************************************************************************
175 
176 
177 //*************************************************************************************************
193 #define BLAZE_TYPELIST_4( T1, T2, T3, T4 ) \
194  TypeList< T1, BLAZE_TYPELIST_3( T2, T3, T4 ) >
195 //*************************************************************************************************
196 
197 
198 //*************************************************************************************************
214 #define BLAZE_TYPELIST_5( T1, T2, T3, T4, T5 ) \
215  TypeList< T1, BLAZE_TYPELIST_4( T2, T3, T4, T5 ) >
216 //*************************************************************************************************
217 
218 
219 //*************************************************************************************************
235 #define BLAZE_TYPELIST_6( T1, T2, T3, T4, T5, T6 ) \
236  TypeList< T1, BLAZE_TYPELIST_5( T2, T3, T4, T5, T6 ) >
237 //*************************************************************************************************
238 
239 
240 //*************************************************************************************************
256 #define BLAZE_TYPELIST_7( T1, T2, T3, T4, T5, T6, T7 ) \
257  TypeList< T1, BLAZE_TYPELIST_6( T2, T3, T4, T5, T6, T7 ) >
258 //*************************************************************************************************
259 
260 
261 //*************************************************************************************************
277 #define BLAZE_TYPELIST_8( T1, T2, T3, T4, T5, T6, T7, T8 ) \
278  TypeList< T1, BLAZE_TYPELIST_7( T2, T3, T4, T5, T6, T7, T8 ) >
279 //*************************************************************************************************
280 
281 
282 //*************************************************************************************************
298 #define BLAZE_TYPELIST_9( T1, T2, T3, T4, T5, T6, T7, T8, T9 ) \
299  TypeList< T1, BLAZE_TYPELIST_8( T2, T3, T4, T5, T6, T7, T8, T9 ) >
300 //*************************************************************************************************
301 
302 
303 //*************************************************************************************************
320 #define BLAZE_TYPELIST_10( T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 ) \
321  TypeList< T1, BLAZE_TYPELIST_9( T2, T3, T4, T5, T6, T7, T8, T9, T10 ) >
322 //*************************************************************************************************
323 
324 
325 
326 
327 //=================================================================================================
328 //
329 // LENGTH OF A TYPE LIST
330 //
331 //=================================================================================================
332 
333 //*************************************************************************************************
349 template< typename TList > // Type of the type list
350 struct Length;
351 //*************************************************************************************************
352 
353 
354 //*************************************************************************************************
359 template<>
360 struct Length< NullType >
361 {
362  //**Member enumeration**************************************************************************
363  enum { value = 0 };
364  //**********************************************************************************************
365 };
367 //*************************************************************************************************
368 
369 
370 //*************************************************************************************************
375 template< typename Head // Type of the head of the type list
376  , typename Tail > // Type of the tail of the type list
377 struct Length< TypeList<Head,Tail> >
378 {
379  //**Member enumeration**************************************************************************
380  enum { value = 1 + Length<Tail>::value };
381  //**********************************************************************************************
382 };
384 //*************************************************************************************************
385 
386 
387 
388 
389 //=================================================================================================
390 //
391 // INDEXED ACCESS
392 //
393 //=================================================================================================
394 
395 //*************************************************************************************************
413 template< typename TList // Type of the type list
414  , size_t Index > // Type list access index
415 struct TypeAt;
416 //*************************************************************************************************
417 
418 
419 //*************************************************************************************************
424 template< typename Head // Type of the head of the type list
425  , typename Tail > // Type of the tail of the type list
426 struct TypeAt< TypeList<Head,Tail>, 0 >
427 {
428  //**Member enumeration**************************************************************************
429  typedef Head Result;
430  //**********************************************************************************************
431 };
433 //*************************************************************************************************
434 
435 
436 //*************************************************************************************************
441 template< typename Head // Type of the head of the type list
442  , typename Tail // Type of the tail of the type list
443  , size_t Index > // Type list access index
444 struct TypeAt< TypeList<Head,Tail>, Index >
445 {
446  //**Member enumeration**************************************************************************
447  typedef typename TypeAt< Tail, Index-1 >::Result Result;
448  //**********************************************************************************************
449 };
451 //*************************************************************************************************
452 
453 
454 
455 
456 //=================================================================================================
457 //
458 // TYPE LIST SEARCH
459 //
460 //=================================================================================================
461 
462 //*************************************************************************************************
483 template< typename TList // Type of the type list
484  , typename Type > // The search type
485 struct Contains;
486 //*************************************************************************************************
487 
488 
489 //*************************************************************************************************
494 template< typename Type > // The search type
495 struct Contains< NullType, Type >
496 {
497  //**Member enumeration**************************************************************************
498  enum { value = 0 };
499  //**********************************************************************************************
500 };
502 //*************************************************************************************************
503 
504 
505 //*************************************************************************************************
510 template< typename Tail // Type of the tail of the type list
511  , typename Type > // The search type
512 struct Contains< TypeList<Type,Tail>, Type >
513 {
514  //**Member enumeration**************************************************************************
515  enum { value = 1 };
516  //**********************************************************************************************
517 };
519 //*************************************************************************************************
520 
521 
522 //*************************************************************************************************
527 template< typename Head // Type of the head of the type list
528  , typename Tail // Type of the tail of the type list
529  , typename Type > // The search type
530 struct Contains< TypeList<Head,Tail>, Type >
531 {
532  //**Member enumeration**************************************************************************
533  enum { value = Contains<Tail,Type>::value };
534  //**********************************************************************************************
535 };
537 //*************************************************************************************************
538 
539 
540 //*************************************************************************************************
572 template< typename TList // Type of the type list
573  , typename Type > // The search type
575 //*************************************************************************************************
576 
577 
578 //*************************************************************************************************
583 template< typename Type > // The search type
584 struct ContainsRelated< NullType, Type >
585 {
586  //**Member enumeration**************************************************************************
587  enum { value = 0 };
588  //**********************************************************************************************
589 };
591 //*************************************************************************************************
592 
593 
594 //*************************************************************************************************
599 template< typename Head // Type of the head of the type list
600  , typename Tail // Type of the tail of the type list
601  , typename Type > // The search type
602 struct ContainsRelated< TypeList<Head,Tail>, Type >
603 {
604  private:
605  //**********************************************************************************************
606  class No {};
607  class Yes { No no[2]; };
608  //**********************************************************************************************
609 
610  //**********************************************************************************************
611  static Yes test( Head );
612  static No test( ... );
613  static Type createType();
614  //**********************************************************************************************
615 
616  //**Member enumeration**************************************************************************
617  enum { tmp = sizeof( test( createType() ) ) == sizeof( Yes ) ? 1 : 0 };
618  //**********************************************************************************************
619 
620  public:
621  //**Member enumeration**************************************************************************
622  enum { value = tmp == 1 ? 1 : ( ContainsRelated<Tail,Type>::value ) };
623  //**********************************************************************************************
624 };
626 //*************************************************************************************************
627 
628 
629 //*************************************************************************************************
648 template< typename TList // Type of the type list
649  , typename Type > // The search type
650 struct IndexOf;
651 //*************************************************************************************************
652 
653 
654 //*************************************************************************************************
659 template< typename Type > // The search type
660 struct IndexOf< NullType, Type >
661 {
662  //**Member enumeration**************************************************************************
663  enum { value = -1 };
664  //**********************************************************************************************
665 };
667 //*************************************************************************************************
668 
669 
670 //*************************************************************************************************
675 template< typename Tail // Type of the tail of the type list
676  , typename Type > // The search type
677 struct IndexOf< TypeList<Type,Tail>, Type >
678 {
679  //**Member enumeration**************************************************************************
680  enum { value = 0 };
681  //**********************************************************************************************
682 };
684 //*************************************************************************************************
685 
686 
687 //*************************************************************************************************
692 template< typename Head // Type of the head of the type list
693  , typename Tail // Type of the tail of the type list
694  , typename Type > // The search type
695 struct IndexOf< TypeList<Head,Tail>, Type >
696 {
697  private:
698  //**Member enumeration**************************************************************************
699  enum { tmp = IndexOf<Tail,Type>::value };
700  //**********************************************************************************************
701 
702  public:
703  //**Member enumeration**************************************************************************
704  enum { value = tmp == -1 ? -1 : 1 + tmp };
705  //**********************************************************************************************
706 };
708 //*************************************************************************************************
709 
710 
711 
712 
713 //=================================================================================================
714 //
715 // APPENDING TO TYPE LISTS
716 //
717 //=================================================================================================
718 
719 //*************************************************************************************************
734 template< typename TList // Type of the type list
735  , typename Type > // The type to be appended to the type list
736 struct Append;
737 //*************************************************************************************************
738 
739 
740 //*************************************************************************************************
745 template<>
746 struct Append< NullType, NullType >
747 {
748  //**Type definitions****************************************************************************
749  typedef NullType Result;
750  //**********************************************************************************************
751 };
753 //*************************************************************************************************
754 
755 
756 //*************************************************************************************************
761 template< typename Type > // The type to be appended to the type list
762 struct Append< NullType, Type >
763 {
764  //**Type definitions****************************************************************************
765  typedef BLAZE_TYPELIST_1( Type ) Result;
766  //**********************************************************************************************
767 };
769 //*************************************************************************************************
770 
771 
772 //*************************************************************************************************
777 template< typename Head // Type of the head of the type list
778  , typename Tail > // Type of the tail of the type list
779 struct Append< NullType, TypeList<Head,Tail> >
780 {
781  //**Type definitions****************************************************************************
782  typedef TypeList<Head,Tail> Result;
783  //**********************************************************************************************
784 };
786 //*************************************************************************************************
787 
788 
789 //*************************************************************************************************
794 template< typename Head // Type of the head of the type list
795  , typename Tail // Type of the tail of the type list
796  , typename Type > // The type to be appended to the type list
797 struct Append< TypeList<Head,Tail>, Type >
798 {
799  //**Type definitions****************************************************************************
800  typedef TypeList< Head, typename Append<Tail,Type>::Result > Result;
801  //**********************************************************************************************
802 };
804 //*************************************************************************************************
805 
806 } // namespace blaze
807 
808 #endif