<br><br><div class="gmail_quote">On Sat, Mar 13, 2010 at 21:13, Walter Bright <span dir="ltr"><<a href="mailto:newshound1@digitalmars.com">newshound1@digitalmars.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Currently, given an array:<br>
<br>
alias T[3] A;<br>
A a;<br>
<br>
the default initializer for A, A.init, is T.init. It is done this way for memory efficiency, as:<br>
<br>
a = A.init;<br>
<br>
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.<br>
<br>
So, I propose changing A.init from being T.init to being [T.init, T.init, T.init].<br>
<br>
What do you think?<br></blockquote><div><br>That's bug 3826<br><br><a href="http://d.puremagic.com/issues/show_bug.cgi?id=3826">http://d.puremagic.com/issues/show_bug.cgi?id=3826</a> <br></div></div><br>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. <br>
I was very surprised to see that A.init was T.init. <br><br>Andrei:<br>>My understanding is that you propose to transform A.init into a literal
with as many elements <br>>as the length of the array. That has a an issue. <br>>Currently array literals default to T[], not T[N]. <br><br>Ah, yes.<br><br>>So this would do the
unexpected:<br>
<br>
>alias int[3] A;<br>
>A a;<br>
>auto b = A.init;<br>
>assert(is(typeof(b) == int[]); // pass<br>
<br>Currently, this does something as unexpected (at least for me):<br><br>assert( !is (typeof(b) == typeof(a))); // b is an int, a is a int[3]<br><br>In parallel to what grauzone said, I think this assert should never fail:<br>
<br>T x;<br>assert(is(typeof(x) == typeof(T.init));<br><br><br>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...<br>
<br><br> Philippe<br><br>