Defining a version after it's tested for
Tim Matthews
tim.matthews7 at gmail.com
Thu May 21 18:03:57 PDT 2009
On Fri, 22 May 2009 07:54:07 +1200, Robert Clipsham
<robert at octarineparrot.com> wrote:
> Steven Schveighoffer wrote:
>> Versions are intended to be predefined before usage. It's the same
>> thing as using a variable before it's defined. The rational is, to
>> flag errors to the user where he thinks forward referencing of versions
>> works.
>> Unfortunately, you have to do the following workaround:
>> version(BackendFoo) { version=BackendFoo_;}
>> else version(BackendBar) { version=BackendBar_;}
>> else version(BackendCar) { version=BackendCar_;}
>> else
>> {
>> version(Windows) {version=BackendFoo_;}
>> }
>> And now, you must use Backend*_ in your code. It should work, but
>> it's ugly.
>> Maybe Walter has a better method.
>> -Steve
>
> Unfortunately I thought this might be the case. Thanks.
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.
More information about the Digitalmars-d
mailing list