tag:blogger.com,1999:blog-36017112.post4789000652929641122..comments2024-03-28T17:08:26.448+00:00Comments on Featherweight Musings: Rust for C++ programmers - part 4: unique pointersUnknownnoreply@blogger.comBlogger7125tag:blogger.com,1999:blog-36017112.post-16635874244521189082014-07-17T12:17:22.478+01:002014-07-17T12:17:22.478+01:00unique_ptr is nullable and does not pass on its co...unique_ptr is nullable and does not pass on its constness to its pointee. In that respect, I like to think of Box<T> as a boost::ptr_container<T> with fixed size of one.Unknownhttps://www.blogger.com/profile/08094391583620054197noreply@blogger.comtag:blogger.com,1999:blog-36017112.post-83379319804510256382014-05-18T01:03:06.861+01:002014-05-18T01:03:06.861+01:00@susu, Rust must be conservative, so if you have a...@susu, Rust must be conservative, so if you have a conditional and a value is moved in one path, then after the conditional, then the value is considered moved.Nick Cameron.https://www.blogger.com/profile/04760749052780174977noreply@blogger.comtag:blogger.com,1999:blog-36017112.post-86213321491164358842014-05-14T20:45:39.320+01:002014-05-14T20:45:39.320+01:00Great post! When I got familiar with C++'s mo...Great post! When I got familiar with C++'s move semantic I realized that it should be the default, not the copying. Of course, it can't be done because of backward-compatibility. But it's cool to see that rust has taken that path! :)<br /><br />However, something is not completely clear to me. You mentioned that:<br /><br /><i>"So, in C++ accessing a unique pointer whose value has moved will result in a runtime error (since it will be null). In Rust this produces a compile time error and you cannot go wrong at runtime."</i><br /><br />But what will happen if I 'move' the unique pointer into a function conditionally. <a href="https://gist.github.com/susu/e4d3f99152322ad892d7#file-gistfile1-rs" rel="nofollow">For example</a>. It can't be checked compile time, since depends on runtime.<br /><br />(Sorry, I could not insert preformatted code here.)susuhttps://www.blogger.com/profile/01182202787592889405noreply@blogger.comtag:blogger.com,1999:blog-36017112.post-35138866152154897702014-04-29T17:29:52.677+01:002014-04-29T17:29:52.677+01:00I also like the box more than ~. let x = uniq 75 w...I also like the box more than ~. let x = uniq 75 would be even better, unless box is used for the other types, too.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-36017112.post-57457208439255426612014-04-29T17:05:45.001+01:002014-04-29T17:05:45.001+01:00More please, and faster :)More please, and faster :)Rasmus Wriedt Larsenhttp://rasmuswriedtlarsen.comnoreply@blogger.comtag:blogger.com,1999:blog-36017112.post-33356161879131056412014-04-29T17:02:42.048+01:002014-04-29T17:02:42.048+01:00This comment has been removed by the author.Unknownhttps://www.blogger.com/profile/09029049366949860844noreply@blogger.comtag:blogger.com,1999:blog-36017112.post-4561521524337548952014-04-29T15:53:02.525+01:002014-04-29T15:53:02.525+01:00~ for allocation changed to box? I like that. It w...~ for allocation changed to box? I like that. It was not that hard to learn that * in C declares and dereferences a pointer, and that & in C++ declares a reference and takes the address of a variable (creates a pointer), but I really don't want any more of that declaration/operation duality...Anonymousnoreply@blogger.com