On Monday, 4 March 2019 at 10:09:19 UTC, drug wrote:
On 04.03.2019 13:03, drug wrote:
insertStable needs DList.Range, not Until!... one. You can do
something like this https://run.dlang.io/is/A2vZjW
Oops, it was wrong example, I'd recommend this way -
https://run.dlang.io/is/ugPL8j
```
import std.algorithm, std.container, std.stdio;
struct DataPoint {
immutable ulong time;
ulong value;
}
void main() {
auto dataPoints = DList!DataPoint([
DataPoint(10_000_000, 1),
DataPoint(30_000_000, 3),
DataPoint(40_000_000, 4),
]);
auto time = 30_000_000;
auto r = findSplit!((a, b) => a.time == b)(dataPoints[],
[time]);
auto dp = dataPoints[].find(r[1].front);
writeln("before: ", dataPoints[]);
dataPoints.insertBefore(dp, DataPoint(20_000_000, 2));
writeln("after: ", dataPoints[]);
}
```
Thanks, seems that using dataPoints[] makes dataPoints usable as
an range. How can I learn more about [] operator? I'm not sure I
understand how is this documented in DList.
Find does the job! What's the difference between find and until?