UniquePtr in D

2013-12-22 Thread Benjamin Thaut
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 implemen

Re: UniquePtr in D

2013-12-22 Thread 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 th

Re: UniquePtr in D

2013-12-22 Thread Benjamin Thaut
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/6e7

Re: UniquePtr in D

2013-12-22 Thread Benjamin Thaut
I also just noticed that std.typecons.Unique does not disable the copy constructor. That doesn't seem very safe to me. The source code for it is also littered with tons of "Doens't work yet" comments.

Re: UniquePtr in D

2013-12-22 Thread Sergei Nosov
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/d1a6

Re: UniquePtr in D

2013-12-22 Thread Benjamin Thaut
Am 22.12.2013 14:36, schrieb Sergei Nosov: 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 s

Re: UniquePtr in D

2013-12-22 Thread Timon Gehr
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

Re: UniquePtr in D

2013-12-22 Thread Timon Gehr
On 12/22/2013 02:19 PM, 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 b

Re: UniquePtr in D

2013-12-22 Thread Timon Gehr
On 12/22/2013 03:13 PM, Timon Gehr wrote: Is error 1 a bug? Because there should cleary not be any copy at this point. ... I don't think the conditions when a struct is moved are actually documented beyond the NRVO case. I think it ideally would be a bug, but this would require some kind of DI

Re: UniquePtr in D

2013-12-22 Thread Timon Gehr
On 12/22/2013 03:19 PM, Timon Gehr wrote: On 12/22/2013 03:13 PM, Timon Gehr wrote: Is error 1 a bug? Because there should cleary not be any copy at this point. ... I don't think the conditions when a struct is moved are actually documented beyond the NRVO case. I think it ideally would be a

Re: UniquePtr in D

2013-12-22 Thread Sergei Nosov
On Sunday, 22 December 2013 at 13:40:30 UTC, Benjamin Thaut wrote: Uh, this looks a lot better then std.typecons.Unique Did you try doing a pull request to replace std.typecons.Unique with your implementation? No, I didn't. I'm kind of thinking, that the "unique" concept currently can't be fu