Dynamic array initialization syntax

Andrej Mitrovic andrej.mitrovich at gmail.com
Wed Feb 16 16:53:15 PST 2011


import std.stdio;
import std.range;

auto newArray(T)(T value, size_t size)
{
    return array(take(repeat(value), size));
}

void main()
{
    auto a1 = newArray(5, 3);
    assert(a1 == [5, 5, 5]);
}


__Dmain:; Function begin, communal
        sub     esp, 28                                 ; 0000 _ 83. EC, 1C
        mov     dword [esp+8H], 5                       ; 0003 _ C7.
44 24, 08, 00000005
        mov     dword [esp+4H], 1                       ; 000B _ C7.
44 24, 04, 00000001
        mov     edx, dword [esp+8H]                     ; 0013 _ 8B. 54 24, 08
        mov     eax, dword [esp+4H]                     ; 0017 _ 8B. 44 24, 04
        push    edx                                     ; 001B _ 52
        push    eax                                     ; 001C _ 50
        call
_D3std5array72__T̔Sزange43״TakeֱֶRepeatTiZ˚ɚƆ>Ɓi; 001D _ E8,
00000000(rel)
        add     esp, 28                                 ; 0022 _ 83. C4, 1C
        xor     eax, eax                                ; 0025 _ 31. C0
        ret                                             ; 0027 _ C3
; __Dmain End of function

Is that good? I can't tell, I'm still working my way around the asm book. :)

But you did say there's an extra __memset32 call in your #2 example in
the bug issue report, and I don't see one here.


More information about the Digitalmars-d mailing list