[Issue 5124] Make std.algorithm.sort weakly pure

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri May 18 10:24:07 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=5124

Dmitry Olshansky <dmitry.olsh at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |dmitry.olsh at gmail.com
         Resolution|---                         |WORKSFORME

--- Comment #2 from Dmitry Olshansky <dmitry.olsh at gmail.com> ---
The provided example now compiles, so whatever changes required were introduced
w/o ever noticing this ticket. Just clarifies my understanding that NOBODY is
looking at enhancements in Bugzilla (except for select few), but rather only
bugs.

///

import std.algorithm: sort;
import std.traits: FunctionAttribute, functionAttributes;

alias FunctionAttribute FA; // shorten the enum name

pure int[] foo1(int[] arr) {
    sort(arr);
    return arr;
}

pure int[] foo2(int[] arr) {
    sort!q{ a > b }(arr);
    return arr;
}

pure bool myComp1(int x, int y) { return x > y; }
pure int[] foo3(int[] arr) {
    sort!(myComp1)(arr);
    return arr;
}

pure int[] foo4(int[] arr) {
    static pure bool myComp2(int x, int y) { return x > y; }
    // static assert(functionAttributes!(myComp2) & FA.PURE); // asserts
    //sort!(myComp2)(arr);
    return arr;
}

void main() {
    assert(foo1([5, 1, 7, 4]) == [1, 4, 5, 7]);
    assert(foo2([5, 1, 7, 4]) == [7, 5, 4, 1]);
    assert(foo3([5, 1, 7, 4]) == [7, 5, 4, 1]);
    //assert(foo4([5, 1, 7, 4]) == [7, 5, 4, 1]);
}

--


More information about the Digitalmars-d-bugs mailing list