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
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.
On Wed, Oct 24, 2012 at 9:53 AM, Jerome jerome.spama...@yahoo.com wrote:
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
Damn, I typed this a bit too fast. I forgot the imports:
Probably, but my solution can be generalized further, to provide a
sort of pattern-matching:
Add:
import std.conv;
import std.stdio;
template match(cases...)
{
auto match(Input...)(Input input)
{
static if
On Wed, Oct 24, 2012 at 9:56 AM, Jerome jerome.spama...@yahoo.com wrote:
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
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.
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,
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 done in C with a simple macro. I
really would like to know to what
On 10/23/2012 11:47 AM, Jerome wrote:
No answer. Should I assume that it is not possible?
If you like to be mistaken, feel free to do that.
http://en.wikipedia.org/wiki/Non_sequitur_%28logic%29
That's something that could be done in C with a simple macro. I really
would like to know to what
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 done
The solution (not variadic though) would be:
mixin template Select!(alias value,
alias if0, alias then0,
alias if1, alias then1,
alias if2, alias then2,
alias thenDefault)
{
switch(value) {
case if0 : { then0(); } break;
case if1 : { then1(); } break;
case if2 :
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, {
12 matches
Mail list logo