Improving version(...)
Lars T. Kyllingstad
public at kyllingen.NOSPAMnet
Mon Oct 18 13:39:32 PDT 2010
On Mon, 18 Oct 2010 21:42:20 +0200, Tomek Sowiński wrote:
> Dnia 18-10-2010 o 18:15:47 F. Almeida <francisco.m.almeida at gmail.com>
> napisał(a):
>
>> The version() { ... } blocks would greatly improve from support of
>> boolean operators, which would make code much more readable.
>>
>> Let us assume, for example, that I have several version identifiers
>> (VERSION1, VERSION2, VERSION3, VERSION4, etc.) and that a block of code
>> may be compiled in the cases of VERSION1 or VERSION3. It would prove
>> the simplest if one could simply use boolean operators to express
>> combinations of valid versions and thus be able to do
>>
>>
>> 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. :)
-Lars
More information about the Digitalmars-d
mailing list