<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2015-01-30 23:47 GMT+09:00 Andrei Alexandrescu via Digitalmars-d <span dir="ltr"><<a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Please advise.</blockquote><div><br></div><div>The new feature, I call it "Partial type deduction", is not only for static array length.</div><div>Examples:</div><div><br></div><div>void main()</div><div>{</div><div>    const[] a1 = [1,2,3];   // a mutable array of const ints</div><div>    static assert(is(typeof(a1) == const(int)[]));</div><div>    a1 ~= 4;                // OK</div><div>    static assert(!__traits(compiles, { a1[0] = 10; }));     // cannot modify const</div><div><br></div><div>    immutable[][$] a2 = [[1,2], [3,4]];  // a static array of mutable dynamic array of immutable ints</div><div>    static assert(is(typeof(a2) == immutable(int)[][2]));</div><div>    static assert(!__traits(compiles, { a2 ~= [[5,6]]; }));  // cannot append to static array</div><div>    a2[0] = [7,8];          // OK</div><div>    assert(a2 == [[7,8], [3,4]]);</div><div>    static assert(!__traits(compiles, { a2[0][0] = 100; })); // cannot modify immutable</div><div>}</div><div><br></div><div>The type deduction will provide powerful way to type variables.</div><div>Yes, ultimately they can be replaced with library function calls, but the call will be ugly and hard to understand. Consider making a2 by using library function. Can you show us a concept design for that?</div><div><br></div><div>And, staticArray function will not work for the following case:</div><div><br></div><div>int function(int)[$] funcs = [</div><div>    a => a + 1,</div><div>    a => a * 2,</div><div>];</div><div><br></div><div>The template lambdas have no type until they applied to the type `int function(int)`. So</div><div><br></div><div>auto funcs = staticArray(</div><div>    a => a + 1,</div><div>    a => a * 2,</div><div>);</div><div><br></div><div>is clearly impossible.</div><div><br></div><div>The core of the feature is a pattern matching for the declared variable type. I believe it will be useful for declarative style programming.</div><div> </div><div>Kenji Hara</div></div></div></div>