Version 1.00
Author: prototype
Copyright (C) 2004 prototypePermission is granted to copy and redistribute this article provided that its contents (including the title, author information, and this copyright claim) are kept intact in the original form.This software is distributed in the hope that it will be Useful, But without Any Warranty; WITHOUT Even The Implied Warranty of Merchantability Or Fitness for a particular purpose.
AbstractThe typelist and relevant concepts are introduced, together with a basic typelist implementation. An elegant, easy-to-use, and macro-free typelist generator is shown.Introduction Typelist, as its name suggests, refers to a (singly-) linked- list "data" structure with the data or elements being types Like the conventional and more familiar singly-linked list data structure, typelist consists of a number of nodes that are arranged in a logically-linear fashion;. specifically, each node conprises two fields : One, Referred To As The "Data Field", Holds The Data; The Other One, Referred To As The "Pointer Field", Stores the Information for Finding The next node. The Pointer Field of The Last Node Normally has a singular "value" indicating the end of the list. typelist is as fundamental and important for C template metaprograming, which is becoming a crucial paradigm in moden C design and programming, as plain array for conventional programming. Examples of applications o f typelist can be found in Andrei Alexandrescu's book: Modern C Design, and also in future installments of this C Metaprogramming series Here I focus on a basic implementation of typelist and a solution to the interesting question:. how to generate a typelist without C- ? type macros A basic implementation of typelist Implementation of typelist can be amazingly simple as long as one knows how to store a data and how to represent a pointer in C template metaprogramming The solutions to the two problems turn out to be the same. - Use typedf. let us Take a look at an example to see how it works. typedef int type; // stores `int 'to` type'
.Type i; // `I 'is of type` int'. this Simple Example Illustrate That After Typedef, `Type 'Is Remembed by The Compiler to Stand for` Int' and thereafter Wherever `Type 'is buy, IT Will work as if it was literally replaced by `int 'This effect is exactly what we want - using a symbol to represent a data (a type) With this understood, storing a data in C template programming is straightforward;.. while the pointer used in typelist can be considered as an alias to the next node, therefore it can also be implemented using a typedef A basic implementation of typelist can be something like template
This works. But it turns out the best value is actually something like `typelist
This challenge comes with two problems to be solved:??. First, how to let the `gen_typelist 'accept variable number of template arguments Second, how to get the wanted typelist The C language supports default values for template parameters Employing this, we can make a template to behave as if it can accept variable number of template arguments For example, template