InsertBefore in DList of structs

drug drug2004 at bk.ru
Mon Mar 4 10:09:19 UTC 2019


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[]);
}

```


More information about the Digitalmars-d-learn mailing list