initializedArray

Philippe Sigaud philippe.sigaud at gmail.com
Tue Dec 20 13:03:34 PST 2011


On Tue, Dec 20, 2011 at 21:20, Andrej Mitrovic
<andrej.mitrovich at gmail.com> wrote:
> On 12/20/11, Dejan Lekic <dejan.lekic at gmail.com> wrote:
>> I would go even further, and give a *function* as an argument -
>> function that will be used to initialise values.
>
> Well I don't know about functions yet, but I did need to use another
> array as an initializer. So the new implementation takes care of that
> via lockstep:

from : http://www.ideone.com/gKFTK :

unittest
{
    auto arr2 = initializedArray!(int[][])([[1, 2], [3, 4]], 2, 2);
    assert(arr2 == [[1, 2], [3, 4]]);
}

1) What's the difference with using auto arr2 == [[1,2],[3,4]].dup;  ?
(I honestly asks, I don't know much about D's assignements)

2) You can get the lengths of [[1,2],[3,4]], so the 2,2 args is
redundant. What happens if you type:

auto arr2 = initializedArray!(int[][])([[1, 2], [3, 4]], 4, 10);

3) I still think you should relax the constraint on the init value's
type. You do not need it to be *exactly* BaseElementType!T. Thats
stops you from writing

auto arr2 = initializedArray!(float[][])(3,  2,3);

4-ish) No need to attribute the rank/BaseElementType code to me :-)


More information about the Digitalmars-d mailing list