On Sun, 27 Feb 2011 09:52:01 -0500, simendsjo <simen.end...@pandavre.com> wrote:

I'm having some problems grokking version.

How would I translate this simple C macro?
#if !defined(IDENT) || !defined(IDENT2)

I've tried the following:
version(!IDENT)
 > identifier or integer expected, not !

!version(IDENT)
 > Declaration expected, not '!'

version(IDENT || IDENT2)
 > found '||' when expecting ')'

version(IDENT) || version(IDENT2)
 > Declaration expected, not '||'


This is just plain ugly:
version(IDENT) {
} else {
   version = NOT_IDENT_OR_IDENT2;
}

version(IDENT2) {
} else {
   version = NOT_IDENT_OR_IDENT2;
}

version(NOT_IDENT_OR_IDENT2) {
   // Finally
}

The or can make things unnecessarily complex, and I've argued in the past that version(x || y) should be allowed. It's sometimes awkward to try and define a version that means x or y.

But here is essentially the way to do your thingy.

version(IDENT)
{
}
else version(IDENT2)
{
}
else
{
   version=NOT_IDENT_OR_IDENT2;
}

version(NOT_IDENT_OR_IDENT2)
{
  ...
}

or if you only use this in one place, just put the ... inside the else clause.

If you can help it, try to avoid versioning this way. Versioning should use positive symbols, not negative ones. I still think an easier OR clause would help quite a bit. The AND clause is pretty easy, just put multiple version statements on the same line.

-Steve

Reply via email to