Function mergeSortTemp

Merge sort, allowing caller to provide a temp variable. This allows recycling instead of repeated allocations. If D is data, T is temp, and U is a ulong* for calculating bubble sort distance, this can be called as mergeSortTemp(D, D, D, T, T, T, U) or mergeSortTemp(D, D, D, T, T, T) where each D has a T of corresponding type.

T[0] mergeSortTemp(alias compFun, T...) (
  T data
)
if (T.length != 0);

Examples

int[] foo = [3, 1, 2, 4, 5].dup;
int[] temp = new uint[5];
mergeSortTemp!("a < b")(foo, temp);
assert(foo == [1, 2, 3, 4, 5]); // The contents of temp will be undefined.
foo = [3, 1, 2, 4, 5].dup;
real bar = [3.14L, 15.9, 26.5, 35.8, 97.9];
real temp2 = new real[5];
mergeSortTemp(foo, bar, temp, temp2);
assert(foo == [1, 2, 3, 4, 5]);
assert(bar == [15.9L, 26.5, 3.14, 35.8, 97.9]);
// The contents of both temp and temp2 will be undefined.