version()
Jonathan M Davis
jmdavisProg at gmx.com
Sun Jan 15 16:37:15 PST 2012
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.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list