Regarding nWayUnion

bearophile bearophileHUGS at lycos.com
Sat Mar 31 15:16:59 PDT 2012


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


More information about the Digitalmars-d-learn mailing list