UniquePtr in D

Benjamin Thaut code at benjamin-thaut.de
Sun Dec 22 05:28:05 PST 2013


Am 22.12.2013 14:24, schrieb Kelet:
> On Sunday, 22 December 2013 at 13:19:48 UTC, Benjamin Thaut wrote:
>> When working with C-libraries in D I often wish for a equivalent of
>> the C++11 unique_ptr. Unfortunately this is not possible in D.
>> Consider the following source code:
>>
>> http://dpaste.dzfl.pl/6e71c815
>>
>> Is error 1 a bug? Because there should cleary not be any copy at this
>> point.
>>
>> Should we implement moving of u so that error 2 goes away? The
>> compiler could move u into the function and move back out afterwards,
>> but that would mean that the contents of u would be invalid for the
>> duration of the function call (unsafe?)
>>
>> Kind Regards
>> Benjamin Thaut
>
> Is std.typecons.Unique[1] not the equivalent of unique_ptr?
>
> [1]: http://dlang.org/phobos/std_typecons.html#.Unique
>
> Regards,
> Kelet

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.


More information about the Digitalmars-d mailing list