Storing templates
BCS
BCS at pathlink.com
Fri Mar 9 09:26:56 PST 2007
Simen wrote:
> Hi.
>
> I'm new to D, and I'm having a little problems using templates for my parser project...
>
> I thought that I could store the functions in a map ala Function[char[]] so I can reference them as functions["TestFunc"], but I don't know how I can store the templates in any sort of list since they have different parameters/return values.
> I know I can store them as void pointers, but then I need to cast them to the right type before I can use them. Then I have to have a switch statement or something to be able to cast it to the correct type based on the function name.
>
You might try a tuple, but that will only work if it is totally const:
list never changes at run time, all indexing is const.
template Tuple!(V...) { alias V Tuple;}
alias Tuple!(Fn!(int), Fn!(float) /* etc */ ) fnList ;
int i;
fnList[0](i);
float f;
fnList[1](f);
More information about the Digitalmars-d-learn
mailing list