D with experimental features like tuple unpacking

Tobias Pankrath tobias at pankrath.net
Fri Mar 22 07:25:05 PDT 2013


On Friday, 22 March 2013 at 14:23:53 UTC, Tobias Pankrath wrote:
>>
>> But there is a reason for this: tuple/structs can contain 
>> heterogeneous type whereas array contains only homogeneous 
>> type..
>> So if you want to index a tuple/struct of say {int,int[128]} 
>> you have to build an array of pointers to these index, 
>> possible but clearly not free..
>> So I wouldn't agree that tuple/struct are 'trivially 
>> substitutable' to array..
>
> No. A tuple is by definition an ordered, finite sequence of 
> elements. There is no problem to index that.
>
> tuple a = {
>    5;
>    true;
>    0.1
> }
> is(typeof(a[0]) == int)
> is(typeof(a[1]) == bool)

>There is no problem to index that.

because the layout should be known at compile time.


More information about the Digitalmars-d mailing list