D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7125 - semi stable sort is not supported
Summary: semi stable sort is not supported
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-17 05:33 UTC by Kenji Hara
Modified: 2014-03-19 22:25 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Kenji Hara 2011-12-17 05:33:37 UTC
Following code does not compile, 

import std.algorithm;
void main()
{
    auto r1 = sort!("a<b", SwapStrategy.unstable)([1,3,2,4]);
    assert(equal(r1, [1,2,3,4]));

    auto r2 = sort!("a<b", SwapStrategy.semistable)([1,3,2,4]);  // Line 7
    assert(equal(r2, [1,2,3,4]));

    auto r3 = sort!("a<b", SwapStrategy.stable)([1,3,2,4]);
    assert(equal(r3, [1,2,3,4]));
}

Output:
C:\dmd2\src\phobos\std\algorithm.d(7001): Error: static assert  (cast(SwapStrategy)1 != cast(SwapStrategy)1) is false
C:\dmd2\src\phobos\std\algorithm.d(6710):        instantiated from here: sortImpl!(result,ss,int[])
test.d(7):        instantiated from here: sort!("a<b",cast(SwapStrategy)1,int[])

Semi-stable sort is stable sort.
So if stable sort is supported, we can implement it with stable sort, at least.
Comment 1 Infiltrator 2014-03-19 22:25:40 UTC
The provided code compiles and runs without problems as of v2.065.