T.init for static arrays?

grauzone none at example.net
Sat Mar 13 12:31:21 PST 2010


Walter Bright wrote:
> Currently, given an array:
> 
>    alias T[3] A;
>    A a;
> 
> the default initializer for A, A.init, is T.init. It is done this way 
> for memory efficiency, as:
> 
>    a = A.init;
> 
> doesn't need to create an array for the rvalue. But it does cause 
> generic programming problems, especially with the advent of static 
> arrays now being passed by value rather than by ref.
> 
> So, I propose changing A.init from being T.init to being [T.init, 
> T.init, T.init].
> 
> What do you think?

This assert should never fail:

T x;
assert(x is T.init);

(Right now it fails for floats because of NaN - can we fix this too? 
"is" should always do byte comparisons.)



More information about the Digitalmars-d mailing list