1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
/*
* Copyright (c) <2002-2009> <Jean-Philippe Barrette-LaPierre>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (curlpp), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef TYPE_LIST_HPP
#define TYPE_LIST_HPP
#include "NullType.hpp"
#define TYPE_LIST_1(T1) utilspp::tl::TypeList<T1, utilspp::NullType>
#define TYPE_LIST_2(T1, T2 ) ::utilspp::tl::TypeList<T1, TYPE_LIST_1( T2)>
#define TYPE_LIST_3(T1, T2, T3 ) ::utilspp::tl::TypeList<T1, TYPE_LIST_2( T2, T3)>
#define TYPE_LIST_4(T1, T2, T3, T4 ) ::utilspp::tl::TypeList<T1, TYPE_LIST_3( T2, T3, T4)>
#define TYPE_LIST_5(T1, T2, T3, T4, T5) \
::utilspp::tl::TypeList<T1, TYPE_LIST_4(T2, T3, T4, T5)>
#define TYPE_LIST_6(T1, T2, T3, T4, T5, T6) \
::utilspp::tl::TypeList<T1, TYPE_LIST_5(T2, T3, T4, T5, T6)>
#define TYPE_LIST_7(T1, T2, T3, T4, T5, T6, T7) \
::utilspp::tl::TypeList<T1, TYPE_LIST_6(T2, T3, T4, T5, T6, T7)>
#define TYPE_LIST_8(T1, T2, T3, T4, T5, T6, T7, T8) \
::utilspp::tl::TypeList<T1, TYPE_LIST_7(T2, T3, T4, T5, T6, T7, T8)>
#define TYPE_LIST_9(T1, T2, T3, T4, T5, T6, T7, T8, T9) \
::utilspp::tl::TypeList<T1, TYPE_LIST_8(T2, T3, T4, T5, T6, T7, T8, T9)>
#define TYPE_LIST_10(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) \
::utilspp::tl::TypeList<T1, TYPE_LIST_9(T2, T3, T4, T5, T6, T7, T8, T9, T10)>
#define TYPE_LIST_11(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) \
::utilspp::tl::TypeList<T1, TYPE_LIST_10(T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)>
#define TYPE_LIST_12(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) \
::utilspp::tl::TypeList<T1, TYPE_LIST_11(T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)>
#define TYPE_LIST_13(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) \
::utilspp::tl::TypeList<T1, TYPE_LIST_12(T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)>
#define TYPE_LIST_14(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) \
::utilspp::tl::TypeList<T1, TYPE_LIST_13(T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)>
#define TYPE_LIST_15(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) \
::utilspp::tl::TypeList<T1, TYPE_LIST_14(T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)>
namespace utilspp
{
namespace tl
{
template<class T, class U>
struct TypeList
{
typedef T head;
typedef U tail;
};
//Calculating length of TypeLists
template<class TList>
struct length;
template<>
struct length<NullType>
{
enum { value = 0 };
};
template<class T, class U>
struct length<TypeList<T, U> >
{
enum { value = 1 + length<U>::value };
};
/**
* Returns the type at a given position (zero-based)
* in TList. If the index is greather than or equal to
* the length of TList, a compile-time error occurs.
*/
template<class TList, unsigned int index>
struct TypeAt;
template<class THead, class TTail>
struct TypeAt<TypeList<THead, TTail>, 0>
{
typedef THead Result;
};
template<class THead, class TTail, unsigned int i>
struct TypeAt<TypeList<THead, TTail>, i>
{
typedef typename TypeAt<TTail, i - 1>::Result Result;
};
/**
* Returns the type at a given position (zero-based)
* in TList. If the index is greather than or equal to
* the length of TList, OutOfBound template class is
* returned.
*/
template<class TList, unsigned int index, class OutOfBound = utilspp::NullType>
struct TypeAtNonStrict;
template<class THead, class TTail, class OutOfBound>
struct TypeAtNonStrict<TypeList<THead, TTail>, 0, OutOfBound>
{
typedef THead Result;
};
template<class THead, class TTail, unsigned int i, class OutOfBound>
struct TypeAtNonStrict<TypeList<THead, TTail>, i, OutOfBound>
{
typedef typename TypeAtNonStrict<TTail, i - 1>::Result Result;
};
template<unsigned int i, class OutOfBound>
struct TypeAtNonStrict<utilspp::NullType, i , OutOfBound>
{
typedef OutOfBound Result;
};
//Searching TypeLists
template<class TList, class T>
struct IndexOf;
template<class T>
struct IndexOf<NullType, T>
{
enum { value = -1 };
};
template<class TTail, class T>
struct IndexOf<TypeList<T, TTail>, T>
{
enum { value = 0 };
};
template<class THead, class TTail, class T>
struct IndexOf<TypeList<THead, TTail>, T>
{
private:
enum { temp = IndexOf<TTail, T>::value };
public:
enum { value = temp == -1 ? -1 : 1 + temp };
};
//Appending to TypeLists
template<class TList, class T>
struct append;
template <>
struct append<NullType, NullType>
{
typedef NullType Result;
};
template<class T>
struct append<NullType, T>
{
typedef TYPE_LIST_1(T) Result;
};
template<class THead, class TTail>
struct append<NullType, TypeList<THead, TTail> >
{
typedef TypeList<THead, TTail> Result;
};
template <class THead, class TTail, class T>
struct append<TypeList<THead, TTail>, T>
{
typedef TypeList<THead, typename append<TTail, T>::Result>
Result;
};
//Erasing a type from a TypeList
template<class TList, class T>
struct erase;
template<class T>
struct erase<NullType, T>
{
typedef NullType Result;
};
template<class T, class TTail>
struct erase<TypeList<T, TTail>, T>
{
typedef TTail Result;
};
template<class THead, class TTail, class T>
struct erase<TypeList<THead, TTail>, T>
{
typedef TypeList<THead, typename erase<TTail, T>::Result>
Result;
};
}
}
#endif
|