Mixin replacement for switch...case?
Jerome
jerome.spamable at yahoo.com
Wed Oct 24 00:53:57 PDT 2012
Thanks Philippe! Great solution!
I have two remarks.
Remark 1: I understand that your mixin will be expanded into
cascaded if...else statements. It would probably be more
efficient to expand into switch...case, don't you think?
Remark 2: I infer from your code that the "delegate" keyword is
not mandatory, so my solution could also be called like this:
mixin Select!(value,
if0, { then0(); },
if1, { then1(); },
if2, { foo(); bar(); },
{ thenDefault(); }
);
instead of:
mixin Select!(value,
if0, delegate { then0(); },
if1, delegate { then1(); },
if2, delegate { foo(); bar(); },
delegate { thenDefault(); }
);
Is that correct?
More information about the Digitalmars-d
mailing list