version vs. static if

Trass3r un at known.com
Fri Sep 23 08:47:16 PDT 2011


Am 23.09.2011, 17:14 Uhr, schrieb Gor F. Gyolchanyan  
<gor.f.gyolchanyan at gmail.com>:

> I suggest to rewrite the version functionality as follows.
> Replace all existing functionality regarding version with a single  
> compile-time
> built-in construct (much like the `is` expression)
>
> version(/* boolean expression */)
>
> , which will returns true if all symbols withing the expression are  
> defined
> (including identifiers) and the expression yields true.
>
> then, the process of version tracking will look like this:
>
> enum MY_API = true;
> enum MY_API_VERSION = 4;
>
> static if(version(MY_API) && version(MY_API_VERSION >= 2))
> {
>    // ...
>    // Note, that if either MY_API or MY_API_VERSION is not defined, the  
> static
> if's expression will be false.
> }

That would unnecessarily and heavily break existing code.
Also it's a good thing to get an error if you want to use enums for  
versioning and they don't exist (including spell check results).


More information about the Digitalmars-d mailing list