This one weird trick allows you to capture loop variables.

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Tue Nov 19 16:50:14 UTC 2024


On 20/11/2024 5:43 AM, Ali Çehreli wrote:
>     I implemented it as a way to deal with visiting each node of a
>     binary tree. Doing that with a range is clunky and unappealing.
> 
> Exactly! I've always thought opApply is one of the most brilliant parts 
> of D. It's easy to see the curly braces of the foreach loop as a lambda 
> anyway.

There are other ways to do it, than just giving it a delegate.

I.e. hidden state struct and then range over it.

Still on my todo list to look into, as it solves the attribute problem 
of opApply also.



More information about the Digitalmars-d mailing list