Extend D's switch statement?

Vlad Levenfeld via Digitalmars-d digitalmars-d at puremagic.com
Fri Jul 10 08:15:44 PDT 2015


On Friday, 10 July 2015 at 09:07:21 UTC, Marc Schütz wrote:
> On Thursday, 9 July 2015 at 22:50:37 UTC, Vlad Levenfeld wrote:
>> On Thursday, 9 July 2015 at 16:08:37 UTC, Timon Gehr wrote:
>>> On 07/09/2015 04:17 PM, Timon Gehr wrote:
>>>> On 07/09/2015 02:54 PM, rsw0x wrote:
>>>>> ...
>>>>> someone was willing to produce.
>>>>
>>>> Someone is often willing to produce awkward language quirks, 
>>>> so I think
>>>> being critical of new additions has some value.
>>>
>>> E.g.
>>>
>>> "Note: Cannot swap values by tuple assignment.
>>>
>>> int x = 1, y = 2;
>>> {x, y} = {y, x};
>>> // Lowered to:
>>> // x = y, y = x;
>>> assert(y == 2);
>>> assert(x == 2);"
>>>
>>> No, please.
>>
>> Couldn't this could be detected at compile-time and temporary 
>> variables created?
>
> Yes, but there needs to be a complete aliasing analysis, e.g.
>
>     int* x, y;
>     // ...
>     {*x, *y} = {*y, *x};
>
> It's probably safer to create the temporaries by default and 
> elide them when the elements are provably non-aliasing.

Yeah true. I really wish we had this. I've got .tuple and 
TypeTuple and .expand proliferating throughout the code I write, 
and I've got a bunch of helper functions for converting between 
them.... it would be really awesome to get rid of that and unify 
everything with this DIP32.


More information about the Digitalmars-d mailing list