On 27.02.2011 17:27, Lars T. Kyllingstad wrote:
On Sun, 27 Feb 2011 15:52:01 +0100, simendsjo 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
}

Here's one nice solution to your problem:

http://www.digitalmars.com/d/archives/digitalmars/D/
Improving_version_..._119799.html#N119846

Basically, he defines an isVersion() template which is true if the
current version is enabled, and false if not.

-Lars


Pretty nice, but I don't like magic strings. I'd rather use my more clunky version.

Reply via email to