On Sat, Mar 13, 2010 at 21:13, Walter Bright <newshou...@digitalmars.com>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? > That's bug 3826 http://d.puremagic.com/issues/show_bug.cgi?id=3826 I'm all for A.init being [T.init (n times)], as it indeed broke some of my code, so thank you for the suggestion Walter. I was very surprised to see that A.init was T.init. Andrei: >My understanding is that you propose to transform A.init into a literal with as many elements >as the length of the array. That has a an issue. >Currently array literals default to T[], not T[N]. Ah, yes. >So this would do the unexpected: >alias int[3] A; >A a; >auto b = A.init; >assert(is(typeof(b) == int[]); // pass Currently, this does something as unexpected (at least for me): assert( !is (typeof(b) == typeof(a))); // b is an int, a is a int[3] In parallel to what grauzone said, I think this assert should never fail: T x; assert(is(typeof(x) == typeof(T.init)); But then I only use small-size static arrays, as parameters in templates. By small, I mean less than a dozen elements. Other using bigger arrays may shout at this change... Philippe