D with experimental features like tuple unpacking

Dmitry Olshansky dmitry.olsh at gmail.com
Fri Mar 22 05:51:03 PDT 2013


22-Mar-2013 16:44, renoX пишет:
> On Friday, 22 March 2013 at 11:14:47 UTC, Dmitry Olshansky wrote:
>> I'd hate any solution that distances ordinary structs, library tuples
>> and fixed-sized arrays.
>
> Are struct/tuples similar to fixed-sized array?
> I thought that both are different because you can select which element
> you access at runtime in an array, but usually this is not possible with
> structs and tuples where this is selected at compile time and then I
> thought about reflection and I'm not so sure..

Fundamentaly there is no difference at all as long as data layout is the 
same.

The fact that you sort of can't easily index tuple of 3 ints as a fixed 
array of 3 ints is a clear indication of a tendency that I find disturbing.

Anyway D is a systems language so you can just blast your way past these 
limitations:

auto abc = Tuple!(int, int, int)(1, 4, 5);

int[3] data = *cast(int[3]*)&abc;

... //now you can

alternatively even to dynamic array:

int[] dynViewOf = (cast(int*)&abc)[0..3];

There is no escaping the fact that it's just a piece of data structured 
in a certain way.

-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list