Good examples of version() algebra in real code
Petar
Petar
Tue May 23 11:29:06 UTC 2023
On Monday, 22 May 2023 at 14:10:24 UTC, Timon Gehr wrote:
> On 22.05.23 13:46, Petar Kirov [ZombineDev] wrote:
>> On Monday, 22 May 2023 at 11:23:32 UTC, Adam D Ruppe wrote:
>>> On Monday, 22 May 2023 at 08:21:50 UTC, Walter Bright wrote:
>>>> Personally, I like to make the core code version-independent
>>>> and OS-independent and hide the variances in separate
>>>> modules. Isn't foo() clean looking?
>>>
>>> http://dpldocs.info/this-week-in-d/Blog.Posted_2023_02_20.html#static-assert-patterns-arguably-harmful-for-porting
>>
>> I agree with you that having the option of using run-time
>> guards like `assert(0)` / `throw new NotImplementedEx()` and
>> even using empty declarations at compile-time is very
>> convenient in practice to get going with a port. On the other
>> hand, I also find a great amount in being able to get an
>> almost complete list of things that I need to fix at
>> compile-time in terms of planning my work.
>
> ```d
> version(Windows) foo();
> else version(linux) bar();
> else version(fail_early) static assert(0);
> else assert(0);
> ```
>
> :o)
Two issues:
* Requires changing all existing code
* Doesn't work for declarations (e.g. defining an `enum`,
`struct`, etc. at module scope)
More information about the Digitalmars-d
mailing list