Defining a version after it's tested for

Tim Matthews tim.matthews7 at gmail.com
Fri May 22 02:13:03 PDT 2009


On Fri, 22 May 2009 20:29:03 +1200, Robert Clipsham  
<robert at octarineparrot.com> wrote:

> Tim Matthews wrote:
>>  I think this would be less ugly:
>>  template vers(char[] V)
>> {
>>      mixin("version(" ~ V ~ ")
>>      {
>>            const bool vers = true;
>>      }
>>      else
>>      {
>>            const bool vers = false;
>>      }");
>> }
>>  static if(vers!("BackendFoo") || vers!("Windows"))
>> {
>>       //
>> }
>> else static if(vers!("BackendBar"))
>> {
>>      //
>> }
>> else static if (vers!("BackendCar"))
>> {
>>     //
>> }
>> else
>> {
>>     //
>> }
>>  I would prefer the normal version statement to work like that directly  
>> though.
>
> This still doesn't solve my problem though, all it does is remove the  
> usage of the version statement, which seems... pointless :S
>


 From what can I see you have a few different posssible versions but when  
no version is defined you can select a default version based on other  
stuff like windows operating system. Rather than modify the versions or  
add aditional to match the system you can create complex 'static if'  
statements which also are a compile time feature but can have other static  
ifs and logical comparisons like '&&' and '||'. When you have put the  
right checks in you can match your select target systems all within a  
single static if.



More information about the Digitalmars-d mailing list