Skip to content

Commit

Permalink
Merge pull request #1197 from andralex/4909
Browse files Browse the repository at this point in the history
Fix issue 4909 - Two suggestions for std.algorithm.schwartzSort()
  • Loading branch information
dnadlinger committed Mar 23, 2013
2 parents 9052288 + aeaf0ca commit 7cba78d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions std/algorithm.d
Expand Up @@ -9100,13 +9100,14 @@ Returns: The initial range wrapped as a $(D SortedRange) with the
predicate $(D (a, b) => binaryFun!less(transform(a),
transform(b))).
*/
SortedRange!(R, ((a, b) => binaryFun!less(transform(a), transform(b))))
SortedRange!(R, ((a, b) => binaryFun!less(unaryFun!transform(a),
unaryFun!transform(b))))
schwartzSort(alias transform, alias less = "a < b",
SwapStrategy ss = SwapStrategy.unstable, R)(R r)
if (isRandomAccessRange!R && hasLength!R)
{
import core.stdc.stdlib;
alias T = typeof(transform(r.front));
alias T = typeof(unaryFun!transform(r.front));
auto xform1 = (cast(T*) malloc(r.length * T.sizeof))[0 .. r.length];
size_t length;
scope(exit)
Expand All @@ -9119,7 +9120,7 @@ schwartzSort(alias transform, alias less = "a < b",
}
for (; length != r.length; ++length)
{
emplace(xform1.ptr + length, transform(r[length]));
emplace(xform1.ptr + length, unaryFun!transform(r[length]));
}
// Make sure we use ubyte[] and ushort[], not char[] and wchar[]
// for the intermediate array, lest zip gets confused.
Expand All @@ -9135,6 +9136,13 @@ schwartzSort(alias transform, alias less = "a < b",
return typeof(return)(r);
}

unittest
{
// issue 4909
Tuple!(char)[] chars;
schwartzSort!"a[0]"(chars);
}

unittest
{
// issue 5924
Expand Down

0 comments on commit 7cba78d

Please sign in to comment.