Small Vectors Proposal

Lionello Lunesu lio at lunesu.remove.com
Wed Jan 31 01:32:24 PST 2007


Andrei Alexandrescu (See Website For Email) wrote:
> Walter Bright wrote:
>> Thank you, this is in line with what I thought you meant. I'm glad I 
>> was right. Your proposal is sensible and well thought out.
>>
>> The only improvement I'd make is instead of:
>>
>> float4 f;
>>
>> Have:
>>
>> float[4] f;
>>
>> i.e. make static arrays of 2,3,4 dimensions have the suggested 
>> properties. I think this is quite doable.
> 
> I don't think this is advisable. It practically introduces an arbitrary 
> discontinuity. Think of a template of T and N that manipulates arrays 
> T[N]. All of a sudden, for certain values of T and N, arrays started 
> being passed around by value.

That difference could be made using different notations:

void func( float[4] ar );  // by value
void funct(T,uint N)( T[N] ar );

void func( float[] ar );   // by ref
void funct(T)( T[] ar );

This makes sense, too, since "float[4] x;" is already allocated on the 
stack.

> What exactly makes small vectors unsuitable for an implementation via 
> library elements? If we distill a list, maybe we also can figure ways in 
> which we can make the language better, not only one special case of it.

This is already very doable, thanks to the possibility of calling global 
functions taking an array as if they were members of the array:

float Length( float[] ar ); // by ref
float[4] ar;
auto len = ar.Length();

L.



More information about the Digitalmars-d mailing list