Mixin replacement for switch...case?
Jerome
jerome.spamable at yahoo.com
Mon Oct 22 06:14:16 PDT 2012
Hi!
This is a question from a complete newbie.
Is there a way to replace switch...case statements by a mixin
template, maybe a variadic mixin template (does such a thing
exist?).
What I would want to achieve is to have this kind of syntax:
mixin Select!(value,
if0, { then0(); },
if1, { then1(); },
if2, { foo(); bar(); },
{ thenDefault(); }
);
to replace this:
switch(value) {
case if0 : { then0(); } break;
case if1 : { then1(); } break;
case if2 : { foo(); bar(); } break;
default : thenDefault();
}
The reason I ask this is because I almost never use fall through
and the verbosity of the switch statement has been driving me
crazy.
More information about the Digitalmars-d
mailing list