UniquePtr in D
Timon Gehr
timon.gehr at gmx.ch
Sun Dec 22 06:04:36 PST 2013
On 12/22/2013 02:36 PM, Sergei Nosov wrote:
> On Sunday, 22 December 2013 at 13:28:05 UTC, Benjamin Thaut wrote:
>> Well yes, but I'm more interrested in moving around the ownership
>> between functions, which works in c++11 because of the move semantics
>> they implemented. This doesn't work in D for the shown reasons.
>
> http://dpaste.dzfl.pl/d1a6f7d0
>
> That's as close as I could get. It doesn't move the parameters outside
> of the function. I workaround it by returning the unique input
> arguments. It's like "here's your object back".
>
> Everything is pretty much safe in @safe mode - as long as you don't pass
> Unique values by reference.
You probably want to fix this:
class C{}
void main(){
auto x = unique!C().pack;
auto y = x.unpack;
auto z = x.unpack;
assert(y.irel is z.irel);
}
More information about the Digitalmars-d
mailing list