www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13965] New: More handy schwartzSort


          Issue ID: 13965
           Summary: More handy schwartzSort
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: Phobos
          Assignee: nobody puremagic.com
          Reporter: bearophile_hugs eml.cc

This is correct code:

void main() {
    import std.algorithm: schwartzSort, SwapStrategy, equal;
    import std.math: abs;
    auto a = [1, -10, 2];
    auto s = a.schwartzSort!(abs, q{a < b}, SwapStrategy.stable);
    assert(s.equal([1, 2, -10]));

For practical reasons I suggest to support this kind of code too:

auto s = a.schwartzSort!(abs, SwapStrategy.stable);

(This means the "less" predicate can be omitted and replaced by the

Jan 10 2015