A small application for Typelist for multiple classes Id - Loki library

xiaoxiao2021-03-06  67

Suppose you have a number of classes, now you want to assign a unique ID to each class. The easiest way is nothing more than manually adding an ID to this class. The premise is that you are confident that the ID of this class does not conflict with other classes, for this, you need to view all other classes of the code. A little better way is to use the GUID generated by the GUID generator so that you can guarantee that the ID of each class is unique. But the length of the GUID128 bit seems to have some waste. In fact, there is such a idea: Let's register these classes to a place, and return a value while registering as a class ID. So what is the container that is registered as these classes? Typelist in the Loki library is an ideal choice. Typelist is like a normal list, but it is "storage" is a TYPE instead of specific data (in fact, Typelist is implemented by template programming, so after compiling, Typelist does not exist, therefore The word "storage" needs to be added to quotation marks). We can add all classes to Typelist and then use indexOf to return each class in TyPelist, to achieve the purpose of achieving the unique ID. Here is the content of Typelist.h in the Loki library, for your reference:

00001 00002 // The Loki Library00003 // Copyright (c) 2001 by Andrei Alexandrescu00004 // This code accompanies the book: 00005 // Alexandrescu, Andrei. "Modern C Design: Generic Programming and Design 00006 // Patterns Applied" Copyright (. c) 2001. Addison-Wesley.00007 // Permission to use, copy, modify, distribute and sell this software for any 00008 // purpose is hereby granted without fee, provided that the above copyright 00009 // notice appear in all copies and that both that copyright notice and this 00010 // permission notice appear in supporting documentation.00011 // The author or Addison-Welsey Longman make no representations about the 00012 // suitability of this software for any purpose. It is provided "as is" 00013 // without express or implied warranty.00015 00016 // Last update: October 10, 200200017 // Reference00018 00019 #ifndef TYPELIST_INC_00020 #define TYPELIST_INC_00021 00022 #include "NullType.h" 00023 #include "TypeManip.h" 00024 00026 //macros TYPELIST_1, TYPELIST_2, ... TYPELIST_5000027 // Each takes a number of arguments equal to its numeric suffix00028 // The arguments are type names. TYPELIST_NN generates a typelist containing 00029 // all types passed as arguments, in that order.00030 / / EXample: Typelist_2 (Char, Int) GENERATES A TYPE Containing CHAR AND INT.00032 00033 #define Typelist_1 (T1) :: Loki :: Typelist 00034 00035 #define Typelist_2 (T1, T2 : LOKI :: Typelist 00036 00037 #define Typelist_3 (T1, T2, T3) :: Loki :: Typelist 00038 00039 #define Typelist_4 (T1 , T2, T3, T4) / 00040 :: LOKI :: Typelist

00041 00042 #define Typelist_5 (T1, T2, T3, T4, T5) / 00043 :: LOKI: Typelist 00044 00045 #define Typelist_6 (T1, T2, T3, T4, T5, T6) / 00046 :: LOKI:: Typelist 00047 00048 #define Typelist_7 (T1, T2, T3, T4, T5, T6, T7) / 00049 :: Loki :: Typelist 00050 00051 #define Typelist_8 (T1, T2, T3, T4, T5, T6, T7, T8) / 00052 :: LOKI :: Typelist 00053 00054 #define Typelist_9 (T1, T2, T3, T4, T5, T6, T7, T8, T9) / 00055 :: LOKI :: Typelist 00056 00057 #define Typelist_10 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) / 00058 :: LOKI :: Typelist 00059 00060 #define Typelist_11 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) / 00061 :: LOKI: Typelist 00062 00063 #define Typelist_12 (T1, T2, T3, T4 , T5, T6, T7, T8, T9, T10, T11, T12) / 00064 :: LOKI: Typelist 00066 00067 #define Typelist_13 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) / 00068 :: LOKI: TYPELIST 00070 00071 #define Typelist_14 (T1, T2, T3, T4, T5, T6, T7, T8, T9 , T10, / 00072 T11, T12, T13, T14) / 00073 :: Loki :: Typelist

00075 00076 #define Typelist_15 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00077 T11, T12, T13, T14, T15) / 00078 :: Loki :: Typelist 00080 00081 #define Typelist_16 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00082 T11, T12, T13, T14, T15, T16) / 00083 :: LOKI: TYPELIST 00085 00086 #define Typelist_17 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00087 T11, T12, T13, T14, T15, T16, T17) / 00088 :: LOKI :: Typelist 00090 00091 #define Typelist_18 (T1, T2, T3, T4, T5, T6, T7, T8, T12, T10, / 00092 T11, T12, T13, T14, T15, T16, T17, T18 / 00093 :: LOKI :: Typelist 00095 00096 #define Typelist_19 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00097 T11, T12, T13, T14, T15, T16, T17, T18, T19) / 00098 :: Loki :: Typelist 00100 00101 #define Typelist_20 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00102 T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) / 00103 :: Loki :: Typelist

00105 00106 #define Typelist_21 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00107 T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) / 00108 :: LOKI :: Typelist 00110 00111 #define Typelist_22 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 0012 T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) / 00113 :: Loki :: Typelist 00115 00116 #define TypeList_23 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00117 T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23) / 00118 :: Loki :: Typelist 00120 00121 #define Typelist_24 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00122 T11, T12, T123, T14, T19, T20, T21, T22, T23, T24) / 00123 :: Loki :: Typelist 00125 00126 #define Typelist_25 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / / ​​00127 T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25) / 00128 :: LOKI :: Typelist

00131 00132 #define Typelist_26 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00133 T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, / 00134 T21, T22, T23, T24, T25, T26) / 00135 :: Loki :: Typelist 00138 00139 #define Typelist_27 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00140 T11, T12, T17, T18, T19, T20, / 00141 T21, T22, T23, T24, T25, T26, T27) / 00142 :: LOKI: : Typelist 00145 00146 #define Typelist_28 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00147 T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, / 00148 T21, T22, T23, T24, T25, T26, T27, T28) / 00149 :: LOKI:: Typelist 00152 00153 #define Typelist_29 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00154 T11, T12, T13, T14, T15, T16, T17, T18 , T19, T20, / 00155 T21, T22, T23, T24, T25, T26, T27, T28, T29) / 00156 :: Loki :: Typelist

00159 00160 #define Typelist_30 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00161 T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, / 00162 T21, T22, T23, T24, T25, T26, T27, T28, T29, T30) / 00163 :: LOKI:: Typelist 00166 00167 #define TYPELIST_31 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00168 T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, / 00169 T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31) / 00170 :: LOKI:: Typelist 00173 00174 #define TYPELIST_32 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00175 T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, / 00176 T21, T2 2, T23, T24, T25, T26, T27, T28, T29, T30, T31, T32) / 00177 :: Loki :: Typelist 00180 00181 #define Typelist_33 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00182 T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, / 00183 T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, T32, T33) / 00184 :: Loki :: Typelist

00187 00188 #define Typelist_34 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00189 T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, / 00190 T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, T32, T33, T34) / 00191 :: Loki :: Typelist 00194 00195 #define Typelist_35 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00196 T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, / 00197 T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, / 00198 T31, T32, T33, T34, T35) / 00199 :: LOKI: : Typelist 00203 00204 #define Typelist_36 (T1, T2, T3, T4, T5 , T6, T7, T8, T9, T10, / 00205 T11, T16, T17, T18, T19, T20, / 00206 T21, T22, T23, T24, T25, T26, T27, T28 , T29, T33, / 00207 T31, T32, T33, T34, T35, T36) / 00208 :: Loki :: Typelist

00212 00213 #define Typelist_37 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00214 T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, / 00215 T21, T22, T23, T24, T25, T26, T27, T28, T29, T33, / 00216 T31, T36, T37) / 00217 :: LOKI:: Typelist 00221 00222 #define Typelist_38 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00223 T11, T12, T13, T18, T19, T20, / 00224 T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, / 00225 T31, T32, T33, T34, T35, T36, T37, T38) / 00226 :: Loki :: Typelist 00230 00231 #define Typelist_39 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00232 T11, T12, T13 , T14, T15, T16, T17, T18, T19, T20, / 00233 T21, T26, T23, T24, T25, T26, T27, T28, T29, T30, / 00234 T31, T32, T33, T34, T35, T36 , T37, T38, T39) / 00235 :: Loki :: Typelist

00239 00240 #define Typelist_40 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00241 T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, / 00242 T21, T22, T23, T24, T25, T26, T27, T28, T29, T33, / 00243 T31, T36, T37, T38, T35, T36, T37, T38, T39, T40) / 00244 :: Loki :: Typelist 00248 00249 #define Typelist_41 (T1, T2, T3, T4, T5, T6, T7, T8, T12, T10, / / ​​0024, T15, T16, T17, T18, T19, T20, / 0024, T21, T22, T23, T24, T25, T26, T27, T28, T29, T32, / 00252 T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41) / 00253 :: Loki :: Typelist 00257 00258 #define Typelist_42 (T1, T2, T3, T4 , T5, T6, T7, T8, T9, T10, / 00259 T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, / 00260 T21, T22, T23, T24, T25, T26, T27 , T28, T29, T30, / 00261 T31, T36, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42) / 00262 :: Loki :: Typelist

00266 00267 #define Typelist_43 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00268 T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, / 00269 T21, T22, T23, T24, T25, T26, T27, T28, T29, T33, //00270 T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43) / 00271 :: Loki :: Typelist 00275 00276 #define Typelist_44 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00277 T11, T12, T17, T14, T15, T16, T17, T18, T19, T20, / 00278 T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, / 00279 T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44 / 00280 :: LOKI :: Typelist 00284 00285 #define Typelist_45 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00286 T11, T12, T13, T14, T15, T16, T17, T18 , T19, T20, / 00287 T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, / 00288 T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, / 00289 T41, T42, T43, T44, T45) / 00290 :: LOKI:: Typelist <

T1, TYPELIST_44 (T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00291 T12, T13, T14, T15, T16, T17, T18, T19, T20, / 00292 T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, / 00293 T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, / 00294 T41, T42, T43, T44, T45) > 00295 00296 #define Typelist_46 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00297 T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, / 00298 T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, / 00299 T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, / 00300 T41, T42, T43 , T44, T45, T46) / 00301 :: LOKI: TYPELIST 00306 00307 #define Typelist_47 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00 308 T11, T12, T13, T14, T19, T20, / 00309 T21, T26, T23, T24, T25, T26, T27, T28, T29, T30, / / ​​00310 T31, T32, T33 , T34, T35, T36, T37, T38, T39, T40, / 00311 T41, T42, T43, T44, T45, T46, T47) / 00312 :: LOKI: Typelist

00317 00318 #define Typelist_48 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00319 T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, / 00320 T21, T22, T23, T24, T25, T26, T27, T28, T29, T33, T34, T35, T36, T37, T38, T39, T40, / 00322 T41, T42, T43, T44, T45, T46, T47, T48) / 00323 :: LOKI :: Typelist 00328 00329 #define Typelist_49 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00330 T11, T12, T13, T14, T19, T20, / 00331 T21, T22, T23, T24, T25, T26, T27, T28, T29, T26, / 00332 T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, / 00333 T41, T42, T43, T44, T45, T46, T47, T48, T49) / 00334 :: LOKI :: Typelist 00339 00340 #define Typelist_50 (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00341 T11, T12, T13, T14, T15 T16, T17, T18, T19, T20, / 00342 T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, / 00343 T31, T32, T33, T34, T35, T36, T37, T38 , T39, T40, / 00344 T41, T42, T43, T44, T45, T46, T47, T48, T49, T50) / 00345 :: Loki :: Typelist <

T1, TYPELIST_49 (T2, T3, T4, T5, T6, T7, T8, T9, T10, / 00346 T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, / 00347 T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, / 00348 T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, / 00349 T41, T42, T43, T44, T45, T46, T47, T48, T49, T50)> 00350 00351 namespace Loki00352 {00354 // class template Typelist00355 // The building block of typelists of any length00356 // Use it through the TYPELIST_NN macros00357 // Defines nested types: 00358 // Head (first element, a non-typelist type by convention) 00359 // Tail (second element, can be another typelist) 00361 00362 template 00363 struct Typelist00364 {00365 typedef T Head; 00366 typedef U Tail; 00367 }; 00368 00369 // typelist utility algorithms00370 00371 namespace TL00372 {00373 00375 // class template MakeTypelist00376 // Takes a number of arguments equal to its numeric suffix00377 // The arguments are typ E Names.00378 // MakeTypelist :: result00379 // Returns a Typelist this of t1, t2, ... 00381 00382 Template00383 <00384 Typename T1 = NullType, Typename T2 = NullType, Typename T3 = NullType, 00385 typename T4 = NullType, typename T5 = NullType, typename T6 = NullType, 00386 typename T7 = NullType, typename T8 = NullType, typename T9 = NullType, 00387 typename T10 = NullType, typename T11 = NullType, typename T12 = NullType, 00388 Typename T13 = NullType, TypeName T14 = NullType, Typename T15 = NullType, 00389 Typename T16 = NullType, Typename T17 =

NullType, typename T18 = NullType00390> 00391 struct MakeTypelist00392 {00393 private: 00394 typedef typename MakeTypelist00395 <00396 T2, T3, T4, 00397 T5, T6, T7, 00398 T8, T9, T10, 00399 T11, T12, T13,00400 T14, T15, T16, 00401 T17, T1800402> 00403 :: Result TailResult; 00404 00405 public: 00406 typedef typelist Result; 00407}; 00408 00409 template <> 00410 struct MakeTypelist <> 00411 {00412 typedef NullType Result; 00413 }; 00414 00416 // class template Length00417 // Computes the length of a typelist00418 // Invocation (TList is a typelist): 00419 // length :: value00420 // returns a compile-time constant containing the length of TList , Not counting00421 // the end terminator (Which by convention is nulltype) 00423 00424 template struct Length; 00425 template <> struct Length 00426 {00427 enum {value = 0}; 00428}; 00429 00430 template 00431 struct Length 00432 {00433 enum {value = 1 length :: value}; 00434}; 00435 00437 // finds the Type At a given index in a typelist00439 // invocation (Tlist is a typelist And index is a compile-time integral 00440 // constant: 00441 // Typeat :: Result00442 // Returns the Type in position 'Index'

in TList00443 // If you pass an out-of-bounds index, the result is a compile-time error00445 00446 template struct TypeAt; 00447 00448 template 00449 struct TypeAt < typelist , 0> 00450 {00451 typedef Head Result; 00452}; 00453 00454 template 00455 struct TypeAt , i> 00456 {00457 typedef typename TypeAt :: Result Result; 00458}; 00459 00461 // class template TypeAtNonStrict00462 // Finds the type at a given index in a typelist00463 // Invocations (TList is a typelist and index is a compile- Time Integral 00464 // constant: 00465 // a) Typeat :: Result00466 // Returns The Type in position 'Index' in Tlist, or NullType IINDEX IS 00467 // Out-of-Bounds00468 // b) Typeat :: Result00469 // Returns The Type in position 'Inde ex 'in TList, or D if index is out-of-bounds00471 00472 template 00474 struct TypeAtNonStrict00475 {00476 typedef DefaultType Result; 00477}; 00478 00479 template 00480 struct TypeAtNonStrict , 0, DefaultType> 00481 {00482 typedef Head Result; 00483}; 00484 00485 template 00486 struct TYPEATNSTRICT <

Typelist , i, DefaultType> 00487 {00488 typedef typename 00489 TypeAtNonStrict :: Result Result; 00490}; 00491 00493 // class template IndexOf00494 // Finds the index of a type INVOCAST00495 // Invocation (TList is a type): 00496 // Indexof :: Value00497 // Returns the position of t in tlist, or nulltype if t is not found in tlist00499 00500 template struct IndexOf; 00501 00502 template 00503 struct IndexOf 00504 {00505 enum {value = -1}; 00506}; 00507 00508 template 00509 struct IndexOf , T> 00510 {00511 enum {value = 0}; 00512}; 00513 00514 template 00515 struct IndexOf , T> 00516 {00517 private: 00518 enum {temp = indexof :: value}; 00519 public: 00520 enum {value = (Temp == -1? -1: 1 TEMP)}}; 00521}; 00522 00524 // Class Template append00525 // Appends a type or a type iRist to another00526 // invocation (Tlist is a type ipelist and t is Either a type or a type ^: 00527 // append :: result00528 // Returns a type is tlist Followed By T And NullType-Terminated00530 00531 Template struct append; 00532 00533 template <> struct append

00534 {00535 typedef NullType Result; 00536}; 00537 00538 template struct Append 00539 {00540 typedef TYPELIST_1 (T) Result; 00541}; 00542 00543 template 00544 struct Append > 00545 {00546 typedef typelist Result; 00547}; 00548 00549 template 00550 struct Append , T > 00551 {00552 typedef typelist :: Result> 00554 Result; 00555}; 00556 00558 // class template Erase00559 // erases the first occurence, if any, of a type in a typelist00560 // invocation (TList is a type): 00561 // ERASE :: result00562 // Returns a type is tlist without the first occurence of t00564 00565 template struct Erase; 00566 00567 template // Specialization 100568 struct Erase 00569 {00570 typedef NullType Result; 00571}; 00572 00573 template / / Specialization 200574 struct Erase , T> 00575 {00576 typedef Tail Result; 00577}; 00578 00579 template // Specialization 300580 struct Erase , T>

00581 {00582 typedef Typelist :: Result> 00584 Result; 00585}; 00586 00588 // class template EraseAll00589 // Erases all first occurences, if any, of a type in a typelist00590 / / Invocation (TList is a typelist and T is a type): 00591 // eraseAll :: Result00592 // returns a typelist that is TList without any occurence of T00594 00595 template struct eraseAll ; 00596 template 00597 struct eraseAll 00598 {00599 typedef NullType Result; 00600}; 00601 template 00602 struct eraseAll , T> 00603 {00604 // Go all the way down the list removing the type00605 typedef typename eraseAll :: Result Result; 00606}; 00607 template 00608 struct eraseAll , T> 00609 {00610 // Go all the way down the list removing the type00611 typedef Typelist :: Result> 00613 Result; 00614}; 00615 00617 // class template NoDuplicates00618 // Removes all duplicate types in a typelist00619 // Invocation (TList is a typelist): 00620 // NoDuplicates :: Result00622 00623 template struct NoDuplicates; 00624 00625 template <> struct NoDuplicates < NullType> 00626 {00627 TypeType Result; 00628};

00629 00630 template 00631 struct NoDuplicates > 00632 {00633 private: 00634 typedef typename NoDuplicates :: Result L1; 00635 typedef typename Erase :: Result L2; 00636 public: 00637 typedef typelist Result; 00638}; 00639 00641 // class template Replace00642 // Replaces the first occurence of a type in a typelist, with another type00643 // Invocation (TList is a typelist, T, u is types): 00644 // Replace :: result00645 // Returns a Typelist in which the first opcurence of t is replaced with u00647 00648 Template Struct Replace; 00649 00650 template 00651 struct Replace 00652 {00653 typedef NullType Result; 00654}; 00655 00656 template 00657 struct Replace , T, U> 00658 {00659 TypedEf Typelist result; 00660}; 00661 00662 Template 00663 struct replace , T, U> 00664 {00665 typedef typelist :: Result> 00667 Result; 00668}; 00669 00671 // class template ReplaceAll00672 // Replaces all occurences of a type in a TYPELIST, WITH Another Type00673 // Invocation (Tlist is a type): 00674 // Replace

:: Result00675 // returns a typelist in which all occurences of T is replaced with U00677 00678 template struct ReplaceAll; 00679 00680 template 00681 struct ReplaceAll 00682 {00683 typedef NullType Result; 00684}; 00685 00686 template 00687 struct ReplaceAll , T, U> 00688 {00689 typedef typelist :: Result> Result; 00690}; 00691 00692 Template 00693 struct replaceall , t, u> 00694 { 00695 typedef typelist :: Result> 00697 Result; 00698}; 00699 00701 // class template Reverse00702 // reverses a typelist00703 // Invocation (TList is a typelist): 00704 / / REV erse :: Result00705 // returns a typelist that is TList reversed00707 00708 template struct Reverse; 00709 00710 template <> 00711 struct Reverse 00712 {00713 typedef NullType Result; 00714}; 00715 00716 template < Class head, class tail> 00717 Struct Reverse > 00718 {00720 TypeName Reverse :: result, head> :: result result; 00721};

00722 00724 // class template MostDerived00725 // Finds the type in a typelist that is the most derived from a given type00726 // Invocation (TList is a typelist, T is a type): 00727 // MostDerived :: Result00728 // returns the type in TList that's the most derived from T00730 00731 template struct MostDerived; 00732 00733 template 00734 struct MostDerived 00735 {00736 typedef T Result; 00737} ; 00738 00739 template 00740 struct MostDerived , T> 00741 {00742 private: 00743 typedef typename MostDerived :: Result Candidate; 00744 public: 00745 TypedEf TypeName Select <00746 SuperSubclass :: Value, 00747 Head, Candidate> :: result result; 00748}; 00749 00751 // Class Template Derivedtofront00752 // Arrang es the types in a typelist so that the most derived types appear first00753 // Invocation (TList is a typelist): 00754 // DerivedToFront :: Result00755 // returns the reordered TList 00757 00758 template struct DerivedToFront; 00759 00760 template <> 00761 struct DerivedToFront 00762 {00763 typedef NullType Result; 00764}; 00765 00766 template 00767 struct DerivedToFront > 00768 {00769 private: 00770 typedef typename MOSTDERIVED

转载请注明原文地址:https://www.9cbs.com/read-110595.html

New Post(0)