to! converting 1D to 2D array

ed growlercab at gmail.com
Thu Mar 13 21:36:27 PDT 2014


On Friday, 14 March 2014 at 04:18:18 UTC, ed wrote:
> On Thursday, 13 March 2014 at 18:17:03 UTC, Chris Williams 
> wrote:
>> On Thursday, 13 March 2014 at 03:31:09 UTC, ed wrote:
>>> On Thursday, 13 March 2014 at 00:15:19 UTC, Chris Williams 
>>> wrote:
>>> [snip]
>>>> It shouldn't and probably isn't working.
>>>
>>> It is working and in fact it is in a "const pure @safe" 
>>> function. So I will trust it  :-)
>>
>> Well it's like a broken watch being correct twice a day. The 
>> correct result doesn't mean that something is working.
>
> But this is perfectly valid and safe D code, is it not?
>
> long[4] a=[1,2,3,4];
> int[2][2] b = a.to!(int[]);
>
> which is no different to this:
>
> int[] a_int = a.to!(int[]);
> int[2][2] b = a_int;
>
> Am I missing something here?
>
> Thanks,
> ed

Looking at the disassembly I'm convinced the code is benign and 
valid D. It just goes through the D runtime which does the full 
array bounds checking.

As to whether or not this should work:

int[4] a=[1,2,3,4];
int[2][2] b;
b=a;

is up to the D language gurus. I think it should... but I'm no 
language developer, there may be other side-effects I haven't 
thought about.

Cheers,
ed



More information about the Digitalmars-d-learn mailing list