Re: Mixin replacement for switch...case?

2012-10-24 Thread Jerome
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? Oh! I've just figured out that it is not a mixin, but a function template.

Re: Mixin replacement for switch...case?

2012-10-24 Thread Jerome
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

Re: Mixin replacement for switch...case?

2012-10-23 Thread Jerome
On Tuesday, 23 October 2012 at 10:40:12 UTC, Daniel Kozák wrote: I think this should be possible, look for eg. to std.bitmanip bitfields template On Tuesday, 23 October 2012 at 09:47:55 UTC, Jerome wrote: No answer. Should I assume that it is not possible? That's something that could be

Re: Mixin replacement for switch...case?

2012-10-23 Thread Jerome
OK. I have done my homework and answered my own question based on the Duff's Device example in the Language Reference page for Mixins. The solution (not variadic though) would be: mixin template Select!(alias value, alias if0, alias then0, alias if1, alias then1, alias if2, alias then2,

Re: Mixin replacement for switch...case?

2012-10-23 Thread Jerome
No answer. Should I assume that it is not possible? That's something that could be done in C with a simple macro. I really would like to know to what extent mixins are a replacement for C macros for generating boilerplate code.

Mixin replacement for switch...case?

2012-10-22 Thread Jerome
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, {