Can I do an or in a version block?

Regan Heath regan at netmail.co.nz
Thu Mar 8 02:13:01 PST 2012


On Thu, 08 Mar 2012 06:12:44 -0000, Jonathan M Davis <jmdavisProg at gmx.com>  
wrote:
> On Thursday, March 08, 2012 06:38:48 Tyler Jameson Little wrote:
>> I would like to do something like this:
>>
>> version (linux || BSD) {
>>      // do something...
>> } else {
>>      version (Windows) {
>>          // do something else
>>      } else {
>>          // do something else
>>          assert(false, "Unsupported operating system");
>>      }
>> }
>>
>> The only way I've been able to do this, is by splitting up the
>> two versions and repeat code.
>>
>> Is there a better way to do this? A static if can do this, so is
>> there a way that I can use a static if somehow?

> <snip>... Walter Bright is completely
> against having anything more complicated with versioning, since he  
> thinks that
> it just engenders bad code and bugs.

IIRC the argument was that we should define version identifiers for  
'features' or 'behaviours' not for platforms, etc.

So, given the 2nd example, instead of:

version (LIBV1 || LIBV2) {
     // include some dirty hacks for old versions
} else {
     // do some new fancy stuff for new features
}

do:

version (LIBV1) version = LIB_OLD
version (LIBV2) version = LIB_OLD

version (LIB_OLD) {
   // dirty hacks
} else {
   // new fancy stuff
}

Regan

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/


More information about the Digitalmars-d-learn mailing list