[Issue 17031] New: isSortedRange uses string comparisons to check for sortedness

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Dec 25 22:35:45 PST 2016


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

          Issue ID: 17031
           Summary: isSortedRange uses string comparisons to check for
                    sortedness
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: greeenify at gmail.com

Have a look at the way find is specialized to take advantage of sorted ranges:

https://github.com/dlang/phobos/blob/master/std/algorithm/searching.d#L1377


    static if (is(typeof(pred == "a == b")))
        enum isDefaultPred = pred == "a == b";
    else
        enum isDefaultPred = false;

...

    static if (is(InputRange : SortedRange!TT, TT) && isDefaultPred)


Yep it does a string comparison and thus if the user defines a custom lambda,
`find` won't take advantage of the sortedness. Moreover if another range
function e.g. retro or find is applied the sortedness is not propagated.

FYI: this was introduced in https://github.com/dlang/phobos/pull/4907

--


More information about the Digitalmars-d-bugs mailing list