Fastest Way to Append Multiple Elements to an Array
zeljkog via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Dec 14 15:52:14 PST 2014
On 15.12.14 00:16, "Nordlöw" wrote:
> or some other trick?
void append(T, Args...)(ref T[] arr, Args args){
arr.length += args.length;
foreach(i, e; args)
arr[$ - args.length + i] = args[i];
}
void main()
{
int[] arr = [1, 2, 3, 4, 5];
arr.append(3, 10, 14);
writeln(arr);
}
output:
[1, 2, 3, 4, 5, 3, 10, 14]
More information about the Digitalmars-d-learn
mailing list