version()

Marco Leise Marco.Leise at gmx.de
Mon Jan 16 02:37:13 PST 2012


Am 16.01.2012, 08:25 Uhr, schrieb Manu <turkeyman at gmail.com>:

> On 16 January 2012 02:37, Jonathan M Davis <jmdavisProg at gmx.com> wrote:
>
>> On Monday, January 16, 2012 02:16:03 Manu wrote:
>> > > As for
>> > >
>> > > version(linux || OSX)
>> > >
>> > > you can use
>> > >
>> > > version(Posix)
>> > >
>> > > It'll include FreeBSD as well, but then again, if something is  
>> common
>> to
>> > > both
>> > > linux and OSX, then it's almost certainly in FreeBSD as well.
>> >
>> > Fair enough, although this is just an example.
>> > In my current case, linux and MinGW are the same, but FreeBSD is
>> different.
>> > You can't rely on predefined unions.
>>
>> True. I'm just saying that in the case of
>>
>> version(linux || OSX)
>>
>> there is a good alternative. Personally, I would have thought that  
>> using &&
>> and || would be permitted, but it's not. But again, I'd have to dig  
>> through
>> the archive to see what exactly Walter's arguments were except that he
>> definitely thought that allowing && and || would lead to worse code. It
>> probably relates to him not wanting to allow !, which I _do_ understand  
>> and
>> agree with. Something like
>>
>> version(Posix)
>> {}
>> else version(Windows)
>> {}
>> else
>>        static assert(0, "Unsupported OS");
>>
>> will catch bugs and save you trouble in comparison to
>>
>> version(Posix)
>> {}
>> else
>> {}
>>
>> Yes, right now. Everything that isn't Posix may be Windows, but that  
>> won't
>> necessarily always be true. So, when it comes to versioning, code should
>> definitely be versioned on what it _is_ rather than what it _isn't_. But
>> that
>> doesn't preclude having && and ||. It's just an argument for  
>> disallowing !.
>> And as you can see by my example, you can essentially _already_ do !
>> thanks to
>> else.
>
>
> The list of version isn't limited to platforms though, not even close.
> There are a bunches of concepts in the list. Including OPTIONAL hardware
> features, which probably make he && operator a requirement in addition to
> ||.

I would like to write:

void main() {
     version(!unittest) {
         run_the_program();
     }
}

This is a case where the trait you check for is so specific that checking  
for the negation has a clear benefit. I agree with your opinion on OS  
versions, which are more like an enum, where you go through it like a  
switch-case.


More information about the Digitalmars-d mailing list