generic array functions and vector operations

Steven Schveighoffer schveiguy at yahoo.com
Mon Aug 18 07:04:41 PDT 2008


"Bent Rasmussen" wrote
>I wanted to test out array operations and create some nice generic 
>functions for dealing with vectors. One function is defined as
>
> A[n] lerp(A, uint n)(A t, A[n] a, A[n] b)
> {
>    return a[] + t * (b[] - a[]);
> }
>
> It looks pretty elegant with array operations, but I can't return a static 
> array. Is this a bug or missing feature and if not how might one get 
> similar elegant syntax without sacrificing efficiency?

missing feature.  It is a (commonly annoying) limitation of the D spec.

To get around it, you can return a struct with the array inside.

struct StaticArray(T, uint n)
{
   T[n] value;
}

StaticArray!(A, n) lerp(A, uint n)...

-Steve 





More information about the Digitalmars-d mailing list