mirror of
https://github.com/dlang/phobos.git
synced 2025-05-02 16:10:45 +03:00
Fix issue 4909
This commit is contained in:
parent
28fad77612
commit
aeaf0caded
1 changed files with 11 additions and 3 deletions
|
@ -9100,13 +9100,14 @@ Returns: The initial range wrapped as a $(D SortedRange) with the
|
||||||
predicate $(D (a, b) => binaryFun!less(transform(a),
|
predicate $(D (a, b) => binaryFun!less(transform(a),
|
||||||
transform(b))).
|
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",
|
schwartzSort(alias transform, alias less = "a < b",
|
||||||
SwapStrategy ss = SwapStrategy.unstable, R)(R r)
|
SwapStrategy ss = SwapStrategy.unstable, R)(R r)
|
||||||
if (isRandomAccessRange!R && hasLength!R)
|
if (isRandomAccessRange!R && hasLength!R)
|
||||||
{
|
{
|
||||||
import core.stdc.stdlib;
|
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];
|
auto xform1 = (cast(T*) malloc(r.length * T.sizeof))[0 .. r.length];
|
||||||
size_t length;
|
size_t length;
|
||||||
scope(exit)
|
scope(exit)
|
||||||
|
@ -9119,7 +9120,7 @@ schwartzSort(alias transform, alias less = "a < b",
|
||||||
}
|
}
|
||||||
for (; length != r.length; ++length)
|
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[]
|
// Make sure we use ubyte[] and ushort[], not char[] and wchar[]
|
||||||
// for the intermediate array, lest zip gets confused.
|
// for the intermediate array, lest zip gets confused.
|
||||||
|
@ -9135,6 +9136,13 @@ schwartzSort(alias transform, alias less = "a < b",
|
||||||
return typeof(return)(r);
|
return typeof(return)(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
// issue 4909
|
||||||
|
Tuple!(char)[] chars;
|
||||||
|
schwartzSort!"a[0]"(chars);
|
||||||
|
}
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
// issue 5924
|
// issue 5924
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue