Tim M wrote:
On Wed, 11 Feb 2009 00:28:21 +1300, bobef <[email protected]> wrote:

I was thinking... what is the point of version() ? It is so inflexible. There is no even version(!...). Why not "static if(version(DMD))" or static if(is(version == DMD))?

Regards,
bobef

You could try something like this:


module Vers;

template vers(char[] V)
{
      mixin("version(" ~ V ~ ")
      {
            const bool vers = true;
      }
      else
      {
            const bool vers = false;
      }");
}

int main()
{
      static if(vers!("X86_64"))
      {
            long a;
            pragma(msg, "64 bit");
      }
      else
      {
            int a;
            pragma(msg, "32 bit");
      }

      a = 2;

      return a;
}


You beat me to it. I actually use this a little here and there. But honestly, I find that the cases where I just want 'version(X){...}else{...}' far outweigh the cases where I want 'X && Y' or the like. While it is technically a hack/workaround, I've been perfectly happy with it.

Now, what would be nice, would be if version() could appear in places it currently can't, following a few rules. In mid-statement, for example, so long as its body is a complete expression. And then the same for mixin expressions. Might be daydreaming too much, there.

Imagine though...

template vers (char[] V) {
    const vers = mixin("version("~V~") {true} else {false}") ;
}

Add to that a deep shorthand syntax a la:

template vers (char[] V) = mixin("version("~V~") {true} else {false}") ;

Okay, I'll come down from the clouds now.

-- Chris Nicholson-Sauls

Reply via email to