Good examples of version() algebra in real code

Timon Gehr timon.gehr at gmx.ch
Mon May 22 14:10:24 UTC 2023


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)


More information about the Digitalmars-d mailing list