Permitted locations of a version condition

Phil Deets pjdeets2 at gmail.com
Thu Oct 29 23:33:40 PDT 2009


On Thu, 29 Oct 2009 19:32:56 -0500, Phil Deets <pjdeets2 at gmail.com> wrote:

> enum Tag
> {
>     A, B, C,
>     version (5) {
>        D, E,
>     }
>     version (7) {
>        F, G,
>     }
>     // ...
> }
>

Thanks to Daniel Keep on the learn newsgroup, I got a workaround working.


template Version(string symbol) {
   mixin("version("~symbol~") immutable Version = true;"~
      " else immutable Version = false;");
}

mixin(q"ENUM
enum Tag
{
    A, B,
ENUM"~(Version!("symbol")?q"ENUM
    C, D,
ENUM":"")~q"ENUM
    E,
}
ENUM");

That's not pretty, but it's good enough for me; so I'll probably not do  
any compiler hacking.



More information about the Digitalmars-d mailing list