People, and their irrational fear of string mixins
BCS
none at anon.com
Tue Dec 8 10:55:30 PST 2009
Hello Simen,
> 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,
I want this (for other reasons).
> and my idea
> of mixin templates, we could instead have this syntax:
>
> int n;
> SwitchCase!( n,
> A, handleA(),
> B, handleB(),
> C, handleC(),
> assert( false )
> );
I think you ca get this to work right now:
SwitchCase!(n).
Case!(A, handleA).
Case!(B, handleB).
Case!(C, handleC).
DefaultFail!();
More information about the Digitalmars-d
mailing list