InsertBefore in DList of structs
r-const-dev
r.const.dev at gmail.com
Mon Mar 4 08:14:03 UTC 2019
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
More information about the Digitalmars-d-learn
mailing list