www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Regarding nWayUnion

Do you know why the nWayUnion() function is designed like that? It requires an
array as argument. This is a simple Merge Sort that shows its usage:


T[] mergeSort(T)(in T[] D) {
    if (D.length < 2)
        return D.dup;
    return array(nWayUnion([mergeSort(D[0 .. $ / 2]), mergeSort(D[$ / 2 ..
$])]));
}


Isn't it better for it to just accept a variable number of arguments?

T[] mergeSort(T)(in T[] D) {
    if (D.length < 2)
        return D.dup;
    return array(nWayUnion(mergeSort(D[0 .. $ / 2]), mergeSort(D[$ / 2 .. $])));
}

Bye,
bearophile
Mar 31 2012