Why version() ?
Tim M
a at b.com
Tue Feb 10 04:32:52 PST 2009
It gets even better with constants and works in static asserts too:
module Vers;
template vers(char[] V)
{
mixin("version(" ~ V ~ ")
{
const bool vers = true;
}
else
{
const bool vers = false;
}");
}
const DigitalMars = "DigitalMars";
const X86 = "X86";
const X86_64 = "X86_64";
const Windows = "Windows";
const Win32 = "Win32";
const Win64 = "Win64";
const LittleEndian = "LittleEndian";
const BigEndian = "BigEndian";
const D_Coverage = "D_Coverage";
const D_Ddoc = "D_Ddoc";
const D_InlineAsm_X86 = "D_InlineAsm_X86";
const D_InlineAsm_X86_64 = "D_InlineAsm_X86_64";
const D_LP64 = "D_LP64";
const D_PIC = "D_PIC";
const none = "none";
const all = "all";
int main()
{
const bool forceLong = false;
static if(vers!(X86_64) || forceLong)
{
long a;
pragma(msg, "64 bit");
}
else
{
int a;
pragma(msg, "32 bit");
}
static assert(vers!(LittleEndian) || vers!(BigEndian), "You are a
weird endian");
a = 2;
return a;
}
More information about the Digitalmars-d
mailing list