On Saturday, 14 January 2017 at 03:20:24 UTC, Ignacious wrote:
switch(x)
{
case X:
q.X = e;
break;
case Y:
q.Y = e;
break
etc...
}
Do you mean that verbatim? Or are the case values strings, like:
switch(x)
{
case "foo":
q.foo = e;
break;
case "bar":
q.bar = e;
break
}
I imagine one could write a string mixin that generates the
cases and assignments but I'm hoping for a more elegant
solution.
In any case, I also can imagine a mixin answer, but not much
better. Unless you want to actually look at the broader picture
and maybe redesign the surrounding code to somehow cleverly get
rid of the switch altogether. The question as it is however
doesn't give the context to make it possible.
Ivan Kazmenko.