Prevent copy of range in foreach

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Aug 30 13:30:12 PDT 2016


On 08/30/2016 12:06 PM, Yuxuan Shui wrote:
> Is there a way to use a range defined with disabled post-blit in
> foreach? In other words, is there a way to prevent foreach from copying
> the range?

It's not possible. You can't do much with such a range anyway. For 
example, even r.take(10) requires to copy.

Why do you want to prevent copying? There may be other ways around the 
issue.

> Should I use move()?

I don't know but I guess you can have a member function to do that.

Ali



More information about the Digitalmars-d-learn mailing list