File indexing completed on 2024-12-01 09:49:18

0001 //krazy:excludeall=license (minor variation on MIT license)
0002 /*
0003  This work is derived from:
0004  ----
0005  The Loki Library
0006  Copyright (c) 2001 by Andrei Alexandrescu                                  //krazy:exclude=copyright
0007  This code accompanies the book:
0008  Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design
0009      Patterns Applied". Copyright (c) 2001. Addison-Wesley.                 //krazy:exclude=copyright
0010  Permission to use, copy, modify, distribute and sell this software for any
0011      purpose is hereby granted without fee, provided that the above copyright
0012      notice appear in all copies and that both that copyright notice and this
0013      permission notice appear in supporting documentation.
0014  The author or Addison-Welsey Longman make no representations about the
0015      suitability of this software for any purpose. It is provided "as is"
0016      without express or implied warranty.
0017  ----
0018 
0019  Simon: Actually we could put a lot more of typelist stuff in here, like
0020         real list management (append, erase, ...) or other things, but
0021     for now I just added the basic typelist and a length template,
0022     to keep compile time at a minimum. If we really need more we can
0023     still add it :)
0024  Holger: Now we add a Template to create the TypeList
0025 */
0026 
0027 /**
0028  * @file ktypelist.h
0029  *
0030  * This file defines typelist structures as well as convenience macros
0031  * to create typelists. Additionally, a few typelist compile-time
0032  * algorithms are provided.
0033  */
0034 
0035 /**
0036  * @defgroup ktypelist Typelist classes, algorithms and macros
0037  *
0038  * Typelists are lists of C++ types of arbitrary length. They are used
0039  * to carry type information at compile-time.
0040  *
0041  * Internally, typelists are represented by the KTypeList template
0042  * class. The KTypeList class uses the recursive structure of
0043  * singly-linked lists which is common in functional programming
0044  * languages:
0045  *
0046  * - an empty list is of type KDE::NullType (the terminal marker)
0047  * - a one-element list with element @c T is of type
0048  *   KTypeList\<T, KDE::NullType\>.
0049  * - a two-element list with elements @c T and @c U is of type
0050  *   KTypeList\<T, KTypeList\<U, KDE::NullType\> \>.
0051  * - an N-Element list with the first element @c T and the remaining
0052  *   elements @c Rest is of type KTypeList\<T, Rest\>.
0053  *
0054  * Note that the last element of a typelist is always KDE::NullType.
0055  * Also note that this is only a convention, it is not enforced by
0056  * anything. But if these rules are broken, the compile-time algorithms
0057  * defined for typelists don't work.
0058  *
0059  * To ease the definition of typelists, there are some macros which
0060  * expand to nested KTypeList definitions. These macros have the form
0061  *
0062  * @code
0063  *   K_TYPELIST_N(T1, T2, ..., TN)
0064  * @endcode
0065  *
0066  * where @c N is the number of types in the list (e.g. K_TYPELIST_3())
0067  *
0068  * In addition to that, and also as the preferred way, there is the
0069  * KMakeTypeList template which takes an arbitrary number of type
0070  * arguments (up to 18) and exports a nested typedef called @c Result
0071  * which equals a KTypeList with the list of provided arguments.
0072  *
0073  * To work with typelists, several compile-time algorithms are provided:
0074  *
0075  * - KTypeListLength: determine the number of elements in a typelist
0076  * - KTypeListIndexOf: find a given type in a typelist
0077  *
0078  * For a detailed discussion about typelists, see the book "Modern C++
0079  * Design: Generic Programming and Design Patterns Applied" by Andrei
0080  * Alexandrescu, and/or the Loki Library at
0081  * <a href="http://sourceforge.net/projects/loki-lib/">http://sourceforge.net/projects/loki-lib/</a>
0082  */
0083 
0084 #ifndef ktypelist_h
0085 #define ktypelist_h
0086 
0087 /**
0088  * @name Typelist macros
0089  *
0090  * Convenience macros for transforming flat type enumerations into the
0091  * recursive typelist structure. For a typelist with @c N items, the
0092  * @c K_TYPELIST_N macro is used. For example:
0093  *
0094  * @code
0095  *  typedef K_TYPELIST_4(char, short, int, long) IntegralTypes;
0096  * @endcode
0097  *
0098  * However, the preferred way is to use the KMakeTypeList template.
0099  *
0100  * @ingroup ktypelist
0101  */
0102 //@{
0103 #define K_TYPELIST_1(T1) KTypeList<T1, ::KDE::NullType>
0104 
0105 #define K_TYPELIST_2(T1, T2) KTypeList<T1, K_TYPELIST_1(T2) >
0106 
0107 #define K_TYPELIST_3(T1, T2, T3) KTypeList<T1, K_TYPELIST_2(T2, T3) >
0108 
0109 #define K_TYPELIST_4(T1, T2, T3, T4) \
0110     KTypeList<T1, K_TYPELIST_3(T2, T3, T4) >
0111 
0112 #define K_TYPELIST_5(T1, T2, T3, T4, T5) \
0113     KTypeList<T1, K_TYPELIST_4(T2, T3, T4, T5) >
0114 
0115 #define K_TYPELIST_6(T1, T2, T3, T4, T5, T6) \
0116     KTypeList<T1, K_TYPELIST_5(T2, T3, T4, T5, T6) >
0117 
0118 #define K_TYPELIST_7(T1, T2, T3, T4, T5, T6, T7) \
0119     KTypeList<T1, K_TYPELIST_6(T2, T3, T4, T5, T6, T7) >
0120 
0121 #define K_TYPELIST_8(T1, T2, T3, T4, T5, T6, T7, T8) \
0122     KTypeList<T1, K_TYPELIST_7(T2, T3, T4, T5, T6, T7, T8) >
0123 
0124 #define K_TYPELIST_9(T1, T2, T3, T4, T5, T6, T7, T8, T9) \
0125     KTypeList<T1, K_TYPELIST_8(T2, T3, T4, T5, T6, T7, T8, T9) >
0126 
0127 #define K_TYPELIST_10(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) \
0128     KTypeList<T1, K_TYPELIST_9(T2, T3, T4, T5, T6, T7, T8, T9, T10) >
0129 
0130 #define K_TYPELIST_11(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) \
0131     KTypeList<T1, K_TYPELIST_10(T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) >
0132 
0133 #define K_TYPELIST_12(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) \
0134     KTypeList<T1, K_TYPELIST_11(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0135                                 T11, T12) >
0136 
0137 #define K_TYPELIST_13(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) \
0138     KTypeList<T1, K_TYPELIST_12(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0139                                 T11, T12, T13) >
0140 
0141 #define K_TYPELIST_14(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0142                       T11, T12, T13, T14) \
0143 KTypeList<T1, K_TYPELIST_13(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0144                             T11, T12, T13, T14) >
0145 
0146 #define K_TYPELIST_15(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0147                       T11, T12, T13, T14, T15) \
0148 KTypeList<T1, K_TYPELIST_14(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0149                             T11, T12, T13, T14, T15) >
0150 
0151 #define K_TYPELIST_16(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0152                       T11, T12, T13, T14, T15, T16) \
0153 KTypeList<T1, K_TYPELIST_15(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0154                             T11, T12, T13, T14, T15, T16) >
0155 
0156 #define K_TYPELIST_17(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0157                       T11, T12, T13, T14, T15, T16, T17) \
0158 KTypeList<T1, K_TYPELIST_16(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0159                             T11, T12, T13, T14, T15, T16, T17) >
0160 
0161 #define K_TYPELIST_18(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0162                       T11, T12, T13, T14, T15, T16, T17, T18) \
0163 KTypeList<T1, K_TYPELIST_17(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0164                             T11, T12, T13, T14, T15, T16, T17, T18) >
0165 
0166 #define K_TYPELIST_19(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0167                       T11, T12, T13, T14, T15, T16, T17, T18, T19) \
0168 KTypeList<T1, K_TYPELIST_18(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0169                             T11, T12, T13, T14, T15, T16, T17, T18, T19) >
0170 
0171 #define K_TYPELIST_20(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0172                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) \
0173 KTypeList<T1, K_TYPELIST_19(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0174                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) >
0175 
0176 #define K_TYPELIST_21(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0177                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) \
0178 KTypeList<T1, K_TYPELIST_20(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0179                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) >
0180 
0181 #define K_TYPELIST_22(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0182                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) \
0183 KTypeList<T1, K_TYPELIST_21(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0184                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) >
0185 
0186 #define K_TYPELIST_23(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0187                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23) \
0188 KTypeList<T1, K_TYPELIST_22(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0189                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23) >
0190 
0191 #define K_TYPELIST_24(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0192                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24) \
0193 KTypeList<T1, K_TYPELIST_23(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0194                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24) >
0195 
0196 #define K_TYPELIST_25(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0197                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25) \
0198 KTypeList<T1, K_TYPELIST_24(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0199                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0200                             T21, T22, T23, T24, T25) >
0201 
0202 #define K_TYPELIST_26(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0203                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0204                       T21, T22, T23, T24, T25, T26) \
0205 KTypeList<T1, K_TYPELIST_25(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0206                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0207                             T21, T22, T23, T24, T25, T26) >
0208 
0209 #define K_TYPELIST_27(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0210                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0211                       T21, T22, T23, T24, T25, T26, T27) \
0212 KTypeList<T1, K_TYPELIST_26(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0213                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0214                             T21, T22, T23, T24, T25, T26, T27) >
0215 
0216 #define K_TYPELIST_28(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0217                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0218                       T21, T22, T23, T24, T25, T26, T27, T28) \
0219 KTypeList<T1, K_TYPELIST_27(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0220                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0221                             T21, T22, T23, T24, T25, T26, T27, T28) >
0222 
0223 #define K_TYPELIST_29(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0224                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0225                       T21, T22, T23, T24, T25, T26, T27, T28, T29) \
0226 KTypeList<T1, K_TYPELIST_28(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0227                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0228                             T21, T22, T23, T24, T25, T26, T27, T28, T29) >
0229 
0230 #define K_TYPELIST_30(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0231                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0232                       T21, T22, T23, T24, T25, T26, T27, T28, T29, T30) \
0233 KTypeList<T1, K_TYPELIST_29(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0234                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0235                             T21, T22, T23, T24, T25, T26, T27, T28, T29, T30) >
0236 
0237 #define K_TYPELIST_31(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0238                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0239                       T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31) \
0240 KTypeList<T1, K_TYPELIST_30(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0241                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0242                             T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31) >
0243 
0244 #define K_TYPELIST_32(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0245                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0246                       T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, T32) \
0247 KTypeList<T1, K_TYPELIST_31(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0248                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0249                             T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, T32) >
0250 
0251 #define K_TYPELIST_33(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0252                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0253                       T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, T32, T33) \
0254 KTypeList<T1, K_TYPELIST_32(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0255                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0256                             T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, T32, T33) >
0257 
0258 #define K_TYPELIST_34(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0259                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0260                       T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, T32, T33, T34) \
0261 KTypeList<T1, K_TYPELIST_33(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0262                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0263                             T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, T32, T33, T34) >
0264 
0265 #define K_TYPELIST_35(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0266                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0267                       T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0268                       T31, T32, T33, T34, T35) \
0269 KTypeList<T1, K_TYPELIST_34(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0270                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0271                             T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0272                             T31, T32, T33, T34, T35) >
0273 
0274 #define K_TYPELIST_36(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0275                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0276                       T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0277                       T31, T32, T33, T34, T35, T36) \
0278 KTypeList<T1, K_TYPELIST_35(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0279                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0280                             T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0281                             T31, T32, T33, T34, T35, T36) >
0282 
0283 #define K_TYPELIST_37(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0284                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0285                       T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0286                       T31, T32, T33, T34, T35, T36, T37) \
0287 KTypeList<T1, K_TYPELIST_36(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0288                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0289                             T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0290                             T31, T32, T33, T34, T35, T36, T37) >
0291 
0292 #define K_TYPELIST_38(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0293                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0294                       T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0295                       T31, T32, T33, T34, T35, T36, T37, T38) \
0296 KTypeList<T1, K_TYPELIST_37(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0297                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0298                             T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0299                             T31, T32, T33, T34, T35, T36, T37, T38) >
0300 
0301 #define K_TYPELIST_39(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0302                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0303                       T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0304                       T31, T32, T33, T34, T35, T36, T37, T38, T39) \
0305 KTypeList<T1, K_TYPELIST_38(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0306                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0307                             T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0308                             T31, T32, T33, T34, T35, T36, T37, T38, T39) >
0309 
0310 #define K_TYPELIST_40(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0311                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0312                       T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0313                       T31, T32, T33, T34, T35, T36, T37, T38, T39, T40) \
0314 KTypeList<T1, K_TYPELIST_39(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0315                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0316                             T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0317                             T31, T32, T33, T34, T35, T36, T37, T38, T39, T40) >
0318 
0319 #define K_TYPELIST_41(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0320                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0321                       T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0322                       T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41) \
0323 KTypeList<T1, K_TYPELIST_40(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0324                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0325                             T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0326                             T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41) >
0327 
0328 #define K_TYPELIST_42(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0329                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0330                       T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0331                       T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42) \
0332 KTypeList<T1, K_TYPELIST_41(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0333                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0334                             T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0335                             T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42) >
0336 
0337 #define K_TYPELIST_43(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0338                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0339                       T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0340                       T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43) \
0341 KTypeList<T1, K_TYPELIST_42(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0342                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0343                             T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0344                             T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43) >
0345 
0346 #define K_TYPELIST_44(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0347                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0348                       T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0349                       T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44) \
0350 KTypeList<T1, K_TYPELIST_43(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0351                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0352                             T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0353                             T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44) >
0354 
0355 #define K_TYPELIST_45(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0356                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0357                       T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0358                       T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
0359                       T41, T42, T43, T44, T45) \
0360 KTypeList<T1, K_TYPELIST_44(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0361                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0362                             T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0363                             T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
0364                             T41, T42, T43, T44, T45) >
0365 
0366 #define K_TYPELIST_46(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0367                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0368                       T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0369                       T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
0370                       T41, T42, T43, T44, T45, T46) \
0371 KTypeList<T1, K_TYPELIST_45(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0372                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0373                             T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0374                             T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
0375                             T41, T42, T43, T44, T45, T46) >
0376 
0377 #define K_TYPELIST_47(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0378                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0379                       T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0380                       T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
0381                       T41, T42, T43, T44, T45, T46, T47) \
0382 KTypeList<T1, K_TYPELIST_46(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0383                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0384                             T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0385                             T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
0386                             T41, T42, T43, T44, T45, T46, T47) >
0387 
0388 #define K_TYPELIST_48(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0389                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0390                       T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0391                       T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
0392                       T41, T42, T43, T44, T45, T46, T47, T48) \
0393 KTypeList<T1, K_TYPELIST_47(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0394                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0395                             T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0396                             T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
0397                             T41, T42, T43, T44, T45, T46, T47, T48) >
0398 
0399 #define K_TYPELIST_49(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0400                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0401                       T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0402                       T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
0403                       T41, T42, T43, T44, T45, T46, T47, T48, T49) \
0404 KTypeList<T1, K_TYPELIST_48(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0405                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0406                             T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0407                             T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
0408                             T41, T42, T43, T44, T45, T46, T47, T48, T49) >
0409 
0410 #define K_TYPELIST_50(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0411                       T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0412                       T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0413                       T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
0414                       T41, T42, T43, T44, T45, T46, T47, T48, T49, T50) \
0415 KTypeList<T1, K_TYPELIST_49(T2, T3, T4, T5, T6, T7, T8, T9, T10, \
0416                             T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, \
0417                             T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, \
0418                             T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, \
0419                             T41, T42, T43, T44, T45, T46, T47, T48, T49, T50) >
0420 //@}
0421 
0422 namespace KDE
0423 {
0424 /**
0425  * @class KDE::NullType
0426  *
0427  * This empty class serves as a terminal marker for typelists.
0428  * The last element in a KTypeList is always this class.
0429  *
0430  * @ingroup ktypelist
0431  */
0432 class NullType;
0433 }
0434 
0435 /**
0436  * The building block of typelists of any length.
0437  * Rather than using it directly, you should use it through the
0438  * KMakeTypeList template class or one of the K_TYPELIST_NN macros,
0439  * such as K_TYPELIST_3().
0440  *
0441  * This struct defines two nested types:
0442  *   @li Head (first element, a non-typelist type by convention),
0443  *       is the same as the type parameter @p T.
0444  *   @li Tail (second element, must be either another typelist
0445  *       or KDE::NullType), is the same as the type parameter @p U.
0446  *
0447  * @param T the head of the type list
0448  * @param U the tail of the type list
0449  *
0450  * @ingroup ktypelist
0451  */
0452 template <class T, class U>
0453 struct KTypeList {
0454     /// first element, a non-typelist type by convention
0455     typedef T Head;
0456     /// second element, must be either another typelist or KDE::NullType
0457     typedef U Tail;
0458 };
0459 
0460 // forward decl.
0461 /**
0462  * @class KTypeListLength
0463  *
0464  * This class template implements a compile-time algorithm
0465  * for processing typelists. It expects one type argument:
0466  * @p TList.
0467  *
0468  * KTypeListLength determines the number of elements (the
0469  * length) of the typelist @p TList and exports it through
0470  * the member @c Value. The length of KDE::NullType is 0.
0471  * Example:
0472  *
0473  * @code
0474  *   typedef KMakeTypeList<char, short, int, long>::Result IntegralTypes;
0475  *   assert(KTypeListLength<IntegralTypes>::Value == 4);
0476  *   assert(KTypeListLength<KDE::NullType>::Value == 0);
0477  * @endcode
0478  *
0479  * @param TList the typelist of which the length is to be
0480  *        calculated
0481  *
0482  * @ingroup ktypelist
0483  */
0484 template <class TList> struct KTypeListLength;
0485 
0486 template <>
0487 struct KTypeListLength<KDE::NullType> {
0488     /**
0489      * Zero length type list.
0490      */
0491     enum { Value = 0 };
0492 };
0493 
0494 template <class T, class U>
0495 struct KTypeListLength< KTypeList<T, U> > {
0496     /**
0497      * The length of the type list.
0498      */
0499     enum { Value = 1 + KTypeListLength<U>::Value };
0500 };
0501 
0502 ///////////////////////////////////////////////////////////////////////////////
0503 // class template IndexOf
0504 // Finds the index of a type in a typelist
0505 // Invocation (TList is a typelist and T is a type):
0506 // IndexOf<TList, T>::value
0507 // returns the position of T in TList, or NullType if T is not found in TList
0508 ////////////////////////////////////////////////////////////////////////////////
0509 
0510 /**
0511  * @class KTypeListIndexOf
0512  *
0513  * This class template implements a compile-time algorithm
0514  * for processing typelists. It expects two type arguments:
0515  * @p TList and @p T.
0516  *
0517  * KTypeListIndexOf finds the index of @p T in @p TList
0518  * starting at 0 and exports it through the @c value member.
0519  * If @p T is not found, @c value is -1. Example:
0520  *
0521  * @code
0522  *   typedef KMakeTypeList<char, short, int, long>::Result IntegralTypes;
0523  *   assert(KTypeListIndexOf<IntegralTypes, int>::value == 3);
0524  *   assert(KTypeListIndexOf<IntegralTypes, double>::value == -1);
0525  * @endcode
0526  *
0527  * @param TList either a KTypeList or KDE::NullType
0528  * @param T the type to search for in the typelist
0529  *
0530  * @ingroup ktypelist
0531  */
0532 template <class TList, class T> struct KTypeListIndexOf;
0533 
0534 template <class T>
0535 struct KTypeListIndexOf<KDE::NullType, T> {
0536     enum { value = -1 };
0537 };
0538 
0539 template <class T, class Tail>
0540 struct KTypeListIndexOf< KTypeList<T, Tail>, T > {
0541     enum { value = 0 };
0542 };
0543 
0544 template <class Head, class Tail, class T>
0545 struct KTypeListIndexOf< KTypeList<Head, Tail>, T > {
0546 private:
0547     enum { temp = KTypeListIndexOf<Tail, T>::value };
0548 public:
0549     enum { value = (temp == -1 ? -1 : 1 + temp) };
0550 };
0551 
0552 /**
0553  * This class template implements a compile-time algorithm
0554  * for generating typelists.
0555  *
0556  * KMakeTypeList the preferred way to create a typelist for you.
0557  * You can specify up to 18 types for the typelist. This template
0558  * class calculates the desired typelist and stores it in the
0559  * nested @c Result typedef. Example:
0560  *
0561  * \code
0562  * typedef KMakeTypeList<MyType1,MyWidget,MyQobject,MyKoffice>::Result Products;
0563  * K_EXPORT_COMPONENT_FACTORY( libmyplugin, KGenericFactory<Products> )
0564  * \endcode
0565  *
0566  * @author Holger Freyther based on the Loki library. See copyright statement at the top
0567  * @ingroup ktypelist
0568  */
0569 template <
0570     typename T1  = KDE::NullType, typename T2  = KDE::NullType, typename T3  = KDE::NullType,
0571     typename T4  = KDE::NullType, typename T5  = KDE::NullType, typename T6  = KDE::NullType,
0572     typename T7  = KDE::NullType, typename T8  = KDE::NullType, typename T9  = KDE::NullType,
0573     typename T10 = KDE::NullType, typename T11 = KDE::NullType, typename T12 = KDE::NullType,
0574     typename T13 = KDE::NullType, typename T14 = KDE::NullType, typename T15 = KDE::NullType,
0575     typename T16 = KDE::NullType, typename T17 = KDE::NullType, typename T18 = KDE::NullType
0576     >
0577 struct KMakeTypeList {
0578 private:
0579     typedef typename KMakeTypeList
0580     <
0581     T2, T3, T4,
0582     T5, T6, T7,
0583     T8, T9, T10,
0584     T11, T12, T13,
0585     T14, T15, T16,
0586     T17, T18
0587     >::Result TailResult;
0588 
0589 public:
0590     /**
0591      * The resulting KTypeList calculated by this compile-time
0592      * algorithm.
0593      */
0594     typedef KTypeList<T1, TailResult> Result;
0595 };
0596 
0597 template <
0598     typename T2, typename T3,
0599     typename T4, typename T5, typename T6,
0600     typename T7, typename T8, typename T9,
0601     typename T10, typename T11, typename T12,
0602     typename T13, typename T14, typename T15,
0603     typename T16, typename T17, typename T18
0604     >
0605 struct KMakeTypeList<KDE::NullType, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18> {
0606     typedef KDE::NullType Result;
0607 };
0608 
0609 template<>
0610 struct KMakeTypeList<> {
0611     typedef KDE::NullType Result;
0612 };
0613 
0614 #endif
0615