Prevent copy of range in foreach
Yuxuan Shui via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Aug 31 07:03:20 PDT 2016
On Tuesday, 30 August 2016 at 20:30:12 UTC, Ali Çehreli wrote:
> 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.
I want to make a hash table that uses std.experiment.allocator.
The bucket is allocated from an allocator, and freed in ~this().
I don't want to copy the whole bucket in this(this).
Maybe I should use a reference counter or something?
>
>> 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