Schnek
typetools.hpp
1 /*
2  * typetools.hpp
3  *
4  * Created on: 19 Feb 2007
5  * Author: Holger Schmitz
6  * Email: holger@notjustphysics.com
7  *
8  * Copyright 2012 Holger Schmitz
9  *
10  * This file is part of Schnek.
11  *
12  * Schnek is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * Schnek is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with Schnek. If not, see <http://www.gnu.org/licenses/>.
24  *
25  */
26 
27 #ifndef SCHNEK_TYPETOOLS_H_
28 #define SCHNEK_TYPETOOLS_H_
29 
30 namespace schnek
31 {
32 
33 struct NullType {};
34 struct EmptyType {};
35 
41 template<class Type>
42 struct Type2Type
43 {
45  typedef Type OriginalType;
46 };
47 
48 
50 // *
51 // * A method to pass type information in an argument without creating a large
52 // * object.
53 // */
54 //template<template<class> class Type>
55 //struct Type2Type1
56 //{
57 // /** the original type */
58 // typedef Type OriginalType;
59 //};
60 
66  template<class H, class T>
67  struct Typelist
68  {
70  typedef H Head;
72  typedef T Tail;
73  };
74 
75  template<class TList, unsigned int index, class DefaultType>
77 
78  template<class Head, class Tail, class DefaultType>
79  struct TypeAtNonStrict<Typelist<Head,Tail>, 0, DefaultType>
80  {
81  typedef Head Result;
82  };
83 
84  template<class DefaultType, unsigned int index>
85  struct TypeAtNonStrict<NullType, index, DefaultType>
86  {
87  typedef DefaultType Result;
88  };
89 
90  template<class Head, class Tail, unsigned int index, class DefaultType>
91  struct TypeAtNonStrict<Typelist<Head,Tail>, index, DefaultType>
92  {
93  typedef typename TypeAtNonStrict<Tail,index-1,DefaultType>::Result Result;
94  };
95 
96 }
97 
98 #define TYPELIST_0 NullType
99 #define TYPELIST_1(T1) schnek::Typelist<T1, schnek::NullType>
100 #define TYPELIST_2(T1, T2) schnek::Typelist<T1, TYPELIST_1(T2)>
101 
102 #endif // SCHNEK_TYPETOOLS_H_
Definition: typetools.hpp:67
Definition: typetools.hpp:34
Type OriginalType
Definition: typetools.hpp:45
T Tail
Definition: typetools.hpp:72
Definition: algo.hpp:30
H Head
Definition: typetools.hpp:70
Definition: typetools.hpp:42
Definition: typetools.hpp:76
Definition: typetools.hpp:33