Initializing "two-dimensional" compile-time enum

Philippe Sigaud philippe.sigaud at gmail.com
Sun Nov 24 12:39:29 PST 2013


On Sun, Nov 24, 2013 at 8:09 PM, Uranuz <neuranuz at gmail.com> wrote:
> As far as I understand I can't use immutable values as template arguments.

Indeed not. They are not defined at compile-time.

> //Some template method
> void foo(string arg)()
> { //Some actions here
>
> }
>
> void main()
> {
>         foreach( name, item; pohodEnumValues )
>         {       foo!(name)(); //I need name at compile time here
>         }
> }
> //-----------------
>
> Because we have only compile time foreach over tuple this is not working.
> Can someone give an advice, please?

I see some possibilities, but they might be a bit overkill. In
increasing order of coding effort:

1) use a tuple (as you suggest in another post)
2) use functions to build the code you want (as a string) and then mix
it in. Using functions, you can use iterative code as much as you
wish.
3) Another, more far-fetched, option is to use a struct. Since your AA
is defined at compile-time, I would not create an AA, but a struct,
crafting it to mimic your AA.


More information about the Digitalmars-d mailing list