Comment #0 by bearophile_hugs — 2014-05-16T07:56:18Z
void main() {
int[10] a;
int[20] b;
int[30] c = a ~ b;
}
Compiled with -O -release -inline -noboundscheck (dmd 2.066alpha) gives:
__Dmain comdat
L0: sub ESP,0F8h
mov ECX,0Ah
xor EAX,EAX
push EBX
push ESI
push EDI
lea EDI,0Ch[ESP]
rep
stosd
mov ECX,014h
lea EDI,03Ch[ESP]
rep
stosd
mov EAX,0Ah
mov EBX,offset FLAT:_D11TypeInfo_Ai6__initZ
push 078h
lea ECX,040h[ESP]
push ECX
push 014h
lea EDX,018h[ESP]
push EDX
push EAX
push EBX
call near ptr __d_arraycatT
add ESP,014h
push EDX
lea ESI,094h[ESP]
push ESI
call near ptr _memcpy
add ESP,0Ch
xor EAX,EAX
pop EDI
pop ESI
pop EBX
add ESP,0F8h
ret
But the compiler should perform that operation without heap allocations. So that should also be writeable:
void main() @nogc {
int[10] a;
int[20] b;
int[30] c = a ~ b;
}
Comment #1 by bearophile_hugs — 2014-06-02T17:37:55Z
Other basic cases that can be supported:
void main() @nogc {
int[2] a = [10, 20];
int[3] b = [40, 50, 60];
int[6] c = a ~ 30 ~ b;
}
Currently DMD 2.066alpha gives:
test.d(4,16): Error: cannot use operator ~ in @nogc function main
test.d(4,16): Error: cannot use operator ~ in @nogc function main