People, and their irrational fear of string mixins
Simen kjaeraas
simen.kjaras at gmail.com
Tue Dec 8 02:55:10 PST 2009
On Mon, 07 Dec 2009 16:55:43 +0100, downs <default_357-line at yahoo.de>
wrote:
> Nick Sabalausky wrote:
>> I just noticed in D1 that the values for the cases in a switch must be
>> known
>> at compile-time (btw, the docs don't seem somewhat vague on that). Is
>> this
>> also true in D2? If so, I don't suppose we could get that changed
>> before the
>> book? It's a real PITA for dynamic code.
>>
>>
>
> I wish they'd get over it.
>
> import tools.base;
>
> ...
>
> mixin(
> ReplaceConcat!(2, "if (x == #) { ! } else",
> "#", "!",
> "A", "handleTheACase; ",
> "B", "handleTheBCase; ",
> "C", "handleTheCCase; "
> )
> ~ " assert(false); "
> );
Now if only D templates handled variadic alias parameters, and my idea of
mixin templates, we could instead have this syntax:
int n;
SwitchCase!( n,
A, handleA(),
B, handleB(),
C, handleC(),
assert( false )
);
--
Simen
More information about the Digitalmars-d
mailing list