YAP: variadic templates via arrays and static foreach
Serg Kovrov
kovrov at no.spam
Thu Aug 10 00:45:11 PDT 2006
* Derek Parnell:
> Let me introduce you to associative arrays ...
>
> //-------------
> import std.c.windows.windows;
> import std.stdio;
>
> alias int function() hdlr;
> hdlr[int] Handlers; // -- AA of handlers.
>
> static this()
> {
> // Initialize the AA
> Handlers[WM_MOVE] = &onMove;
> Handlers[WM_CREATE] = &onCreate;
> Handlers[WM_CLOSE] = &onClose;
> }
Thanks Derek, sure it is nice solution for this case. I use this exact
technique for xml parsing rules definition. And it would be even nicer
to have static initialization of static associative arrays... Hope
Walter get tired of regular requests for it and will implement it
eventually =)
I wonder if static associative arrays lookups works as fast as switch
statement?
But original idea was to mixin some cases to switch in a sophisticated
(possibly library) function. Sure my example were simple, but thats for
not overflood message with example code.
More information about the Digitalmars-d
mailing list