Re: switch to member

2017-01-14 Thread Meta via Digitalmars-d-learn
On Saturday, 14 January 2017 at 16:05:33 UTC, Ignacious wrote: Go join the Nazi Youth group, you OSS Sympathizer! What?

Re: switch to member

2017-01-14 Thread Ignacious via Digitalmars-d-learn
On Saturday, 14 January 2017 at 11:32:10 UTC, Marc Schütz wrote: You can utilize a little-known `switch` syntax trick in combination with `foreach`. Because a `foreach` over tuples is unrolled at compile time, it works even if your fields don't have exactly the same types:

Re: switch to member

2017-01-14 Thread Ignacious via Digitalmars-d-learn
On Saturday, 14 January 2017 at 08:30:04 UTC, Meta wrote: On Saturday, 14 January 2017 at 05:29:49 UTC, Nicholas Wilson wrote: enum XX { X = Q.X.offsetof, Y = Q.Y.offsetof //ect. } and then *(cast(void*)(this) + x) = e; //if inside struct/class or *(cast(void*)(q) + x) = e; // if

Re: switch to member

2017-01-14 Thread Ivan Kazmenko via Digitalmars-d-learn
On Saturday, 14 January 2017 at 11:32:10 UTC, Marc Schütz wrote: You can utilize a little-known `switch` syntax trick in combination with `foreach`. Because a `foreach` over tuples is unrolled at compile time, it works even if your fields don't have exactly the same types: That looks

Re: switch to member

2017-01-14 Thread Marc Schütz via Digitalmars-d-learn
You can utilize a little-known `switch` syntax trick in combination with `foreach`. Because a `foreach` over tuples is unrolled at compile time, it works even if your fields don't have exactly the same types: -- struct Foo { int

Re: switch to member

2017-01-14 Thread Meta via Digitalmars-d-learn
On Saturday, 14 January 2017 at 05:29:49 UTC, Nicholas Wilson wrote: enum XX { X = Q.X.offsetof, Y = Q.Y.offsetof //ect. } and then *(cast(void*)(this) + x) = e; //if inside struct/class or *(cast(void*)(q) + x) = e; // if outside Unfortunately this loses you `@safe`ty, but as

Re: switch to member

2017-01-13 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 14 January 2017 at 03:20:24 UTC, Ignacious wrote: When doing common functionality for a switch, is there any way to optimize: switch(x) { case X: q.X = e; break; case Y: q.Y = e; break etc... } e is basically a value that, depending