Jump to page: 1 2
Thread overview
Conditional Compilation Multiple Versions
Jun 13, 2015
bitwise
Jun 13, 2015
Mike Parker
Jun 13, 2015
anonymous
Jun 13, 2015
ketmar
Jun 13, 2015
bitwise
Jun 13, 2015
Márcio Martins
Jun 13, 2015
bitwise
Jun 13, 2015
ketmar
Jun 13, 2015
bitwise
Jun 13, 2015
ketmar
Oct 20, 2016
Claude
Jan 06, 2017
Claude
Jan 06, 2017
Mike Parker
Jan 06, 2017
Claude
Jan 08, 2017
Joakim
Jan 09, 2017
Claude
June 13, 2015
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
June 13, 2015
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) {
    ...
}
June 13, 2015
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...
June 13, 2015
On Fri, 12 Jun 2015 20:55:51 -0400, Márcio Martins <marcioapm@gmail.com> wrote:

> I know... I too hate that one can't use simple logic ops...

Indeed...

Thanks.

  Bit
June 13, 2015
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.

June 13, 2015
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")
{
    ...
}

June 13, 2015
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
June 13, 2015
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.

June 13, 2015
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.
> 
> Any idea what the rationale was for not allowing it?

i don't remember. that murmuring about "it makes the code harder to read" goes beyond me, so it's hard to remember.

June 13, 2015
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
« First   ‹ Prev
1 2