On Monday, 17 July 2017 at 18:38:16 UTC, Nordlöw wrote:
On Monday, 17 July 2017 at 17:46:42 UTC, ag0aep6g wrote:
int[n + m] result = a ~ b;
Further, the expression `a ~ b` here will allocate and create a
copy on the GC-heap before writing `result`.
Maybe LDC optimizes away this now or in the future but DMD
cannot.
Yeah I know, kind of dumb but that's how it is currently.
we have special code in the compiler to optimize a ~ b ~ c.
So all you need to do make it so
auto cat(T[]...)(T args)
{
T[] result;
mixin(() {
string mix = `result = `;
foreach(i;args.length)
{
mix ~= `args[` ~ itos(i) ~ `] ~`;
}
mix[$-1] = ';';
return mix;
}());
return result;
}
that should do it :)