Improving version(...)
Tomek Sowiński
just at ask.me
Mon Oct 18 13:45:37 PDT 2010
Dnia 18-10-2010 o 22:39:32 Lars T. Kyllingstad
<public at kyllingen.nospamnet> napisał(a):
>>> version(VERSION1 || VERSION3)
>>> {
>>> // ...
>>> }
>>
>> You can have it now:
>>
>> template isVersion(string ver) {
>> enum bool isVersion = !is(typeof({
>> mixin("version(" ~ ver ~") static assert(0);");
>> }));
>> }
>>
>> static if (isVersion"VERSION1" || isVersion!"VERSION3") {
>> ...
>> }
>>
>> If you're rushing to reply "That's hideous!", don't bother. I know.
> Actually, I think it's pretty cool.
Heh, thanks. Maybe with more templates it won't poke the eye:
static if (anySatisfy!(isVersion, "VERSION1", "VERSION2", "VERSION3", ...))
Still, it is a hack around a language's restriction. But what would be
programming without one! :)
--
Tomek
More information about the Digitalmars-d
mailing list