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: nob...@puremagic.com
          Reporter: greeen...@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

--

Reply via email to