www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21183] New: schwartzSort does not strip const


          Issue ID: 21183
           Summary: schwartzSort does not strip const
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: minor
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: default_357-line yahoo.de

Consider the following code:

import std.algorithm : schwartzSort;
import std.array : array;

struct S
    int i;
    const(int) foo() { return i; }

void main()
    auto list = [S(4), S(3), S(2)];
    assert(list.dup.schwartzSort!(a => a.foo).array == [S(2), S(3), S(4)]);

This leads to cryptic errors due to the fact that `schwartzSort` does not strip
the `const` from `const(int)` for its internal array, even though it trivially
could since it's a value type.

Aug 21 2020