22-Mar-2013 17:41, renoX пишет:
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.
But there is a reason for this: tuple/structs can contain heterogeneous
type whereas array contains only homogeneous type..
Surely I know this don't you think ? ;)
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..
This example is trivially done with single point provided you know the
layout/padding. There are ways to peek at that in D too.
In general yes, heterogeneous is what makes structs and tuples standout.
So I wouldn't agree that tuple/struct are 'trivially substitutable' to
array..
In the case of exactly the same data layout they do. Plenty of cases are
like this e. g. 2-d, 3-d points being structs. These could be treated
as arrays easily.
Otherwise it is a good idea to not try to when it doesn't make sense.
--
Dmitry Olshansky