Jump to page: 1 2
Thread overview
"version" private word
Oct 31, 2017
Igor Shirkalin
Oct 31, 2017
Jacob Carlborg
Oct 31, 2017
Igor Shirkalin
Oct 31, 2017
bauss
Oct 31, 2017
Dr. Assembly
Oct 31, 2017
Igor Shirkalin
Oct 31, 2017
Dr. Assembly
Oct 31, 2017
Jacob Carlborg
Oct 31, 2017
Jonathan M Davis
Oct 31, 2017
Jesse Phillips
Oct 31, 2017
Igor Shirkalin
Oct 31, 2017
Jesse Phillips
Oct 31, 2017
Igor Shirkalin
Oct 31, 2017
Igor Shirkalin
Nov 01, 2017
Basile B.
October 31, 2017
Hello!

We need some conditional compilation using 'version'.
Say we have some code to be compiled for X86 and X86_64.
How can we do that using predefined (or other) versions?
Examples:

   version(X86 || X86_64) // failed
   version(X86) || version(X86_64) // failed


The following works but it is too verbose:

version(X86) {
	version = X86_or_64;
}
version(X86_64) {
	version = X86_or_64;
}


 - IS
October 31, 2017
On 2017-10-31 14:46, Igor Shirkalin wrote:
> Hello!
> 
> We need some conditional compilation using 'version'.
> Say we have some code to be compiled for X86 and X86_64.
> How can we do that using predefined (or other) versions?
> Examples:
> 
>     version(X86 || X86_64) // failed
>     version(X86) || version(X86_64) // failed
> 
> 
> The following works but it is too verbose:
> 
> version(X86) {
>      version = X86_or_64;
> }
> version(X86_64) {
>      version = X86_or_64;
> }

The only alternative is to do something like this:

version (X86)
    enum x86 = true;
else
    enum x86 = false;

else version (X86_64)
    enum x86_64 = true;
else
    enum x86_64 = false;

static if (x86 || x86_64) {}

-- 
/Jacob Carlborg
October 31, 2017
On Tuesday, 31 October 2017 at 13:53:54 UTC, Jacob Carlborg wrote:
> On 2017-10-31 14:46, Igor Shirkalin wrote:
>> Hello!
>> 
>> We need some conditional compilation using 'version'.
>> Say we have some code to be compiled for X86 and X86_64.
>> How can we do that using predefined (or other) versions?
>> Examples:
>> 
>>     version(X86 || X86_64) // failed
>>     version(X86) || version(X86_64) // failed
>> 
>> 
>> The following works but it is too verbose:
>> 
>> version(X86) {
>>      version = X86_or_64;
>> }
>> version(X86_64) {
>>      version = X86_or_64;
>> }
>
> The only alternative is to do something like this:
>
> version (X86)
>     enum x86 = true;
> else
>     enum x86 = false;
>
> else version (X86_64)
>     enum x86_64 = true;
> else
>     enum x86_64 = false;
>
> static if (x86 || x86_64) {}

Got it. Thank you!
October 31, 2017
On Tuesday, 31 October 2017 at 13:46:40 UTC, Igor Shirkalin wrote:
> Hello!
>

You goal should be to describe features.

Version x86
... Version = I can stand on my head
...

October 31, 2017
On Tuesday, 31 October 2017 at 14:22:37 UTC, Jesse Phillips wrote:
> On Tuesday, 31 October 2017 at 13:46:40 UTC, Igor Shirkalin wrote:
>> Hello!
>>
>
> You goal should be to describe features.
>
> Version x86
> ... Version = I can stand on my head
> ...

pardon?
October 31, 2017
On Tuesday, 31 October 2017 at 14:25:19 UTC, Igor Shirkalin wrote:
> On Tuesday, 31 October 2017 at 14:22:37 UTC, Jesse Phillips wrote:
>> On Tuesday, 31 October 2017 at 13:46:40 UTC, Igor Shirkalin wrote:
>>> Hello!
>>>
>>
>> You goal should be to describe features.
>>
>> Version x86
>> ... Version = I can stand on my head
>> ...
>
> pardon?

Sorry I hate writing code on mobile.

You can create an arbitrary version by assigning a symbol to it, use that symbol to describe a feature, assign that symbol for each architecture that supports it. Then write code in a version block of that symbol.
October 31, 2017
On Tuesday, 31 October 2017 at 14:31:17 UTC, Jesse Phillips wrote:
> On Tuesday, 31 October 2017 at 14:25:19 UTC, Igor Shirkalin wrote:
>> On Tuesday, 31 October 2017 at 14:22:37 UTC, Jesse Phillips wrote:
>>> On Tuesday, 31 October 2017 at 13:46:40 UTC, Igor Shirkalin wrote:
>>>> Hello!
>>>>
>>>
>>> You goal should be to describe features.
>>>
>>> Version x86
>>> ... Version = I can stand on my head
>>> ...
>>
>> pardon?
>
> Sorry I hate writing code on mobile.
>
> You can create an arbitrary version by assigning a symbol to it, use that symbol to describe a feature, assign that symbol for each architecture that supports it. Then write code in a version block of that symbol.

The question was not about mobile platforms. Sometimes we need to mix some combinations of code in one big project with or without some libraries, algorithms etc.
I see what you mean and practically agree with you. But not everything depends on you (us).



October 31, 2017
On Tuesday, 31 October 2017 at 13:53:54 UTC, Jacob Carlborg wrote:
> On 2017-10-31 14:46, Igor Shirkalin wrote:
>> Hello!
>> 
>> We need some conditional compilation using 'version'.
>> Say we have some code to be compiled for X86 and X86_64.
>> How can we do that using predefined (or other) versions?
>> Examples:
>> 
>>     version(X86 || X86_64) // failed
>>     version(X86) || version(X86_64) // failed
>> 
>> 
>> The following works but it is too verbose:
>> 
>> version(X86) {
>>      version = X86_or_64;
>> }
>> version(X86_64) {
>>      version = X86_or_64;
>> }
>
> The only alternative is to do something like this:
>
> version (X86)
>     enum x86 = true;
> else
>     enum x86 = false;
>
> else version (X86_64)
>     enum x86_64 = true;
> else
>     enum x86_64 = false;
>
> static if (x86 || x86_64) {}

Why is that keyword called enum? is this any related to the fact enumeration's field are const values? it would be called invariable or something?
October 31, 2017
On 10/31/17 10:47 AM, Igor Shirkalin wrote:
> On Tuesday, 31 October 2017 at 14:31:17 UTC, Jesse Phillips wrote:
>> On Tuesday, 31 October 2017 at 14:25:19 UTC, Igor Shirkalin wrote:
>>> On Tuesday, 31 October 2017 at 14:22:37 UTC, Jesse Phillips wrote:
>>>> On Tuesday, 31 October 2017 at 13:46:40 UTC, Igor Shirkalin wrote:
>>>>> Hello!
>>>>>
>>>>
>>>> You goal should be to describe features.
>>>>
>>>> Version x86
>>>> ... Version = I can stand on my head
>>>> ...
>>>
>>> pardon?
>>
>> Sorry I hate writing code on mobile.
>>
>> You can create an arbitrary version by assigning a symbol to it, use that symbol to describe a feature, assign that symbol for each architecture that supports it. Then write code in a version block of that symbol.
> 
> The question was not about mobile platforms.

I think he meant he didn't like writing code in a forum post on his mobile, so he wrote something more abstract :)

> Sometimes we need to mix some combinations of code in one big project with or without some libraries, algorithms etc.
> I see what you mean and practically agree with you. But not everything depends on you (us).

The above response has been the standard D answer for as long as this question has been asked (and it has been asked a lot). Walter is dead-set against allowing boolean expressions in version statements.

The anointed way is to divide your code by feature support, and then version those features in/out based on the platform you are on.

For example, instead of "X86_or_X64", you would do "TryUsingSSE" or something (not sure what your specific use case is).

However, enums and static if can be far more powerful. Version statements do not extend across modules, so you may have to repeat the entire scaffolding to establish versions in multiple modules. Enums are accessible across modules.

-Steve
October 31, 2017
On Tuesday, 31 October 2017 at 14:54:27 UTC, Dr. Assembly wrote:
> On Tuesday, 31 October 2017 at 13:53:54 UTC, Jacob Carlborg wrote:
>> On 2017-10-31 14:46, Igor Shirkalin wrote:
>>> [...]
>>
>> The only alternative is to do something like this:
>>
>> version (X86)
>>     enum x86 = true;
>> else
>>     enum x86 = false;
>>
>> else version (X86_64)
>>     enum x86_64 = true;
>> else
>>     enum x86_64 = false;
>>
>> static if (x86 || x86_64) {}
>
> Why is that keyword called enum? is this any related to the fact enumeration's field are const values? it would be called invariable or something?

You're right. Enum defines constant or group of constants in compile time.
The full description of enum can be found here: https://dlang.org/spec/enum.html
« First   ‹ Prev
1 2