[Issue 20751] New: SortedRange with ref predicate parameters fails
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Sun Apr 19 21:05:25 UTC 2020
    
    
  
https://issues.dlang.org/show_bug.cgi?id=20751
          Issue ID: 20751
           Summary: SortedRange with ref predicate parameters fails
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: schveiguy at yahoo.com
Consider a predicate that accepts ref parameters for sort:
----
import std;
bool pred(ref int a, ref int b)
{
   return a < b;
}
void main()
{
   auto sortedArr = [5,4,3,2,1].sort!pred;
   auto rng = sortedArr.equalRange(3);
}
---
onlineapp.d(11): Error: template std.range.SortedRange!(int[], pred,
cast(SortedRangeOptions)0).SortedRange.equalRange cannot deduce function from
argument types !()(int), candidates are:
/dlang/dmd/linux/bin64/../../src/phobos/std/range/package.d(10991):       
equalRange(V)(V value)
  with V = int
  must satisfy the following constraint:
       isTwoWayCompatible!(predFun, ElementType!Range, V)
---
The gist of it is, isTwoWayCompatible assumes the predicate must work for
rvalues. But there is no such requirement for sorting.
This is quite important when sorting large structures.
I don't know if this is a bug for SortedRange, or on isTwoWayCompatible.
Perhaps the refness needs to be told to isTwoWayCompatible?
--
    
    
More information about the Digitalmars-d-bugs
mailing list