foreach over pointers OR foreach that mutates the iterator

Las via Digitalmars-d digitalmars-d at puremagic.com
Thu Jan 26 08:36:14 PST 2017


On Thursday, 26 January 2017 at 11:32:09 UTC, ZombineDev wrote:
> Anyway, another solution is to use refRange:
>
> void main() {
>     import std.range : refRange;
>     S s;
>     auto p = refRange(&s);
>     foreach(i; p)
>         writeln(i);
> }
>
> That way you don't need to dereference 'p' everytime you want 
> to iterate over it. Plus, it should compose well with other 
> range wrappers / algorithms.

This is really helpful; thanks!


More information about the Digitalmars-d mailing list