Re: adding delegate to opApply

2019-09-03 Thread berni via Digitalmars-d-learn
On Monday, 2 September 2019 at 14:20:11 UTC, Paul Backus wrote: If you have an existing delegate that you want to use with opApply, the easiest way is like this: void delegate(Thing) myDelegate = ...; foreach(thing; things) { myDelegate(thing); } // Equivalent to: things.opApply((Thing

Re: adding delegate to opApply

2019-09-02 Thread Paul Backus via Digitalmars-d-learn
On Monday, 2 September 2019 at 12:43:31 UTC, berni wrote: I need to pass the delegate add_new_way somehow to opApply. Here I managed this, by adding this delegate to the remove-delegate and safe it away for further use. This works, because if remove is never called, add_new_way is not used

adding delegate to opApply

2019-09-02 Thread berni via Digitalmars-d-learn
I've tried to make a small example, but it's not easy to get this reduced further. At least I didn't manage. The following program can also be found at https://run.dlang.io/is/p6l7xN void main() { auto foo = Ways([Way([8,2,3,0]),Way([4,6,2]),Way([4,7,2,6])]); foo.remove_odds();