On 04.03.2019 11:14, r-const-dev wrote:
I have a DList of structs, DataPoint, ordered by a struct field, time. I'm trying to insert a new entry preserving order, so I'm trying to use `until` to find the insertion point and `insertBefore` with the result.

struct DataPoint {
     immutable ulong time;
     ulong value;
}

void main() {
     DList!DataPoint dataPoints;
     void incrementAt(ulong time) {
         auto dataPoint = until!(dp => dp.time >= time)(dataPoints);
         if (dataPoint.time == time) {
             ++dataPoint.value;
         } else {
             dataPoints.insertBefore(dataPoint, DataPoint(time, 1));
         }
     }
}

But I'm getting:

/dlang/dmd/linux/bin64/../../src/phobos/std/algorithm/searching.d(4898): Error: template instance `onlineapp.main.incrementAt.Until!(__lambda2, DList!(DataPoint), void)` does not match template declaration Until(alias pred, Range, Sentinel) if (isInputRange!Range) onlineapp.d(14): Error: template instance `onlineapp.main.incrementAt.until!((dp) => dp.time >= time, DList!(DataPoint))` error instantiating

dataPoints itself isn't a range, you need to use dataPoints[]. Also
insertStable needs DList.Range, not Until!... one. You can do something like this https://run.dlang.io/is/A2vZjW

Reply via email to