Thread overview | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
June 13, 2015 Conditional Compilation Multiple Versions | ||||
---|---|---|---|---|
| ||||
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 Re: Conditional Compilation Multiple Versions | ||||
---|---|---|---|---|
| ||||
Posted in reply to bitwise | 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 Re: Conditional Compilation Multiple Versions | ||||
---|---|---|---|---|
| ||||
Posted in reply to bitwise | 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 Re: Conditional Compilation Multiple Versions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Márcio Martins | 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 Re: Conditional Compilation Multiple Versions | ||||
---|---|---|---|---|
| ||||
Posted in reply to bitwise Attachments: | 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 Re: Conditional Compilation Multiple Versions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker | 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 Re: Conditional Compilation Multiple Versions | ||||
---|---|---|---|---|
| ||||
Posted in reply to ketmar | 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 Re: Conditional Compilation Multiple Versions | ||||
---|---|---|---|---|
| ||||
Posted in reply to anonymous Attachments: | 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 Re: Conditional Compilation Multiple Versions | ||||
---|---|---|---|---|
| ||||
Posted in reply to bitwise Attachments: | 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 Re: Conditional Compilation Multiple Versions | ||||
---|---|---|---|---|
| ||||
Posted in reply to ketmar | 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
|
Copyright © 1999-2021 by the D Language Foundation