www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17031] New: isSortedRange uses string comparisons to check


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

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


    static if (is(typeof(pred == "a == b")))
        enum isDefaultPred = pred == "a == b";
        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

Dec 25 2016