www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Conditional Compilation Multiple Versions

reply bitwise <bitwise.pvt gmail.com> writes:
Is there a way to compile for multiple conditions?

Tried all these:

version(One | Two){ }
version(One || Two){ }
version(One && Two){ }
version(One) |  version(Two){ }
version(One) || version(Two){ }
version(One) && version(Two){ }

   Bit
Jun 12 2015
next sibling parent reply Mike Parker <aldacron gmail.com> writes:
On 6/13/2015 9:41 AM, bitwise wrote:
 Is there a way to compile for multiple conditions?

 Tried all these:

 version(One | Two){ }
 version(One || Two){ }
 version(One && Two){ }
 version(One) |  version(Two){ }
 version(One) || version(Two){ }
 version(One) && version(Two){ }

    Bit
// config.d version(One) enum One = true; else enum One = false; version(Two) enum Two = true; else enum Two = false; // other.d import config; static if(One || Two) { ... }
Jun 12 2015
parent reply "anonymous" <anonymous example.com> writes:
On Saturday, 13 June 2015 at 00:47:37 UTC, Mike Parker wrote:
 // config.d
 version(One) enum One = true;
 else enum One = false;

 version(Two) enum Two = true;
 else enum Two = false;

 // other.d
 import config;
 static if(One || Two) {
     ...
 }
Taking it one step further: template Version(string name) { mixin(" version("~name~") enum Version = true; else enum Version = false; "); } static if(Version!"One" || Version!"Two") { ... }
Jun 13 2015
parent reply ketmar <ketmar ketmar.no-ip.org> writes:
On Sat, 13 Jun 2015 13:49:49 +0000, anonymous wrote:

 Taking it one step further:
=20
 template Version(string name)
 {
      mixin("
          version("~name~") enum Version =3D true;
          else enum Version =3D false;
      ");
 }
=20
 static if(Version!"One" || Version!"Two")
 {
      ...
 }
very elegant.=
Jun 13 2015
parent bitwise <bitwise.pvt gmail.com> writes:
On Sat, 13 Jun 2015 12:20:40 -0400, ketmar <ketmar ketmar.no-ip.org> wrote:

 On Sat, 13 Jun 2015 13:49:49 +0000, anonymous wrote:

 Taking it one step further:

 template Version(string name)
 {
      mixin("
          version("~name~") enum Version = true;
          else enum Version = false;
      ");
 }

 static if(Version!"One" || Version!"Two")
 {
      ...
 }
very elegant.
Elegant indeed, but I think my pull request would be frowned upon if I tried to use this in druntime. Bit
Jun 13 2015
prev sibling next sibling parent reply =?UTF-8?B?Ik3DoXJjaW8=?= Martins" <marcioapm gmail.com> writes:
On Saturday, 13 June 2015 at 00:42:00 UTC, bitwise wrote:
 Is there a way to compile for multiple conditions?
version(One) version = OneOrTwo; else version(Two) version = OneOrTwo; version(OneOrTwo) { writeln("moo"); } --- version(One) version(Two) version = OneAndTwo; version(OneAndTwo) { writeln("moo moo"); } I know... I too hate that one can't use simple logic ops...
Jun 12 2015
parent bitwise <bitwise.pvt gmail.com> writes:
On Fri, 12 Jun 2015 20:55:51 -0400, M=E1rcio Martins <marcioapm gmail.co=
m>  =

wrote:

 I know... I too hate that one can't use simple logic ops...
Indeed... Thanks. Bit
Jun 12 2015
prev sibling parent reply ketmar <ketmar ketmar.no-ip.org> writes:
On Fri, 12 Jun 2015 20:41:59 -0400, bitwise wrote:

 Is there a way to compile for multiple conditions?
=20
 Tried all these:
=20
 version(One | Two){ }
 version(One || Two){ }
 version(One && Two){ }
 version(One) |  version(Two){ }
 version(One) || version(Two){ }
 version(One) && version(Two){ }
=20
    Bit
nope. Walter is against that, so we'll not have it, despite the=20 triviality of the patch.=
Jun 13 2015
parent reply bitwise <bitwise.pvt gmail.com> writes:
On Sat, 13 Jun 2015 08:21:50 -0400, ketmar <ketmar ketmar.no-ip.org> wrote:

 On Fri, 12 Jun 2015 20:41:59 -0400, bitwise wrote:

 Is there a way to compile for multiple conditions?

 Tried all these:

 version(One | Two){ }
 version(One || Two){ }
 version(One && Two){ }
 version(One) |  version(Two){ }
 version(One) || version(Two){ }
 version(One) && version(Two){ }

    Bit
nope. Walter is against that, so we'll not have it, despite the triviality of the patch.
Any idea what the rationale was for not allowing it? Bit
Jun 13 2015
parent ketmar <ketmar ketmar.no-ip.org> writes:
On Sat, 13 Jun 2015 12:01:29 -0400, bitwise wrote:

 nope. Walter is against that, so we'll not have it, despite the
 triviality of the patch.
=20 Any idea what the rationale was for not allowing it?
i don't remember. that murmuring about "it makes the code harder to read"=20 goes beyond me, so it's hard to remember.=
Jun 13 2015