Why does std.range.zip use emplace instead of simple assignments?

Timon Gehr timon.gehr at gmx.ch
Thu Sep 1 05:19:56 PDT 2011


On 09/01/2011 10:23 AM, David Nadlinger wrote:
> It might well be that I'm missing something obvious in the emplace()
> overload jungle, but what is the reason for std.range.zip to use
> std.conv.emplace for assigning the range elements to the »output«
> elements instead of just using the assignment operator?
>
> https://github.com/D-Programming-Language/phobos/blob/master/std/range.d#L3022
>
> https://github.com/D-Programming-Language/phobos/blob/master/std/range.d#L3058
>
> (and a few other instances)
>
> I'm asking because this is breaking zip() for ranges of class instances
> (the »assignment« overload of emplace() is not defined for them), and
> I'm wondering about the best way to fix it.
>
> Thanks,
> David

This is there to get move semantics, for efficiency. It avoids calling 
the postblit constructor.
This does not apply to ranges that are classes, so the solution would be 
to add a special case for classes.


More information about the Digitalmars-d-learn mailing list