{"action":"created","issue":{"url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3139","labels_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3139/labels{/name}","comments_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3139/comments","events_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3139/events","html_url":"https://github.com/D-Programming-Language/phobos/pull/3139","id":65958505,"number":3139,"title":"Improve std.typecons.Unique","user":{"login":"mrkline","id":493463,"avatar_url":"https://avatars.githubusercontent.com/u/493463?v=3","gravatar_id":"","url":"https://api.github.com/users/mrkline","html_url":"https://github.com/mrkline","followers_url":"https://api.github.com/users/mrkline/followers","following_url":"https://api.github.com/users/mrkline/following{/other_user}","gists_url":"https://api.github.com/users/mrkline/gists{/gist_id}","starred_url":"https://api.github.com/users/mrkline/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrkline/subscriptions","organizations_url":"https://api.github.com/users/mrkline/orgs","repos_url":"https://api.github.com/users/mrkline/repos","events_url":"https://api.github.com/users/mrkline/events{/privacy}","received_events_url":"https://api.github.com/users/mrkline/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":24,"created_at":"2015-04-02T16:01:40Z","updated_at":"2015-04-13T13:37:14Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3139","html_url":"https://github.com/D-Programming-Language/phobos/pull/3139","diff_url":"https://github.com/D-Programming-Language/phobos/pull/3139.diff","patch_url":"https://github.com/D-Programming-Language/phobos/pull/3139.patch"},"body":"Whenever D is brought up to the general programming public, the garbage collector is quickly raised as a point of contention. Regardless of how legitimate or well-informed these concerns are or are not, it would be a massive public relations boon — and great for the language, to boot — if we could trot out a solid set of RAII-based smart pointers for those who prefer to use them. We have a solid start in `std.typecons.Unique` and `std.typecons.RefCounted`. Unfortunately, these seem to be victims of bit rot and compiler bugs of days long gone.\r\n\r\nThis is the first of several pull requests that attempt to clean these up. An overview of the changes in this request is as follows (updated 2015-04-13):\r\n\r\n- `std.algorithm.move` is used instead of a special `release` member function. Whether by design or by happy accident, `move` transfers ownership between `Unique` pointers in a very similar manner to C++'s `std::move` with `std::unique_ptr`. Along with being a familiar paradigm to C++ users, using `move` to transfer ownership makes more intuitive sense and builds consistency with the rest of Phobos.\r\n\r\n- With `std.algorithm.move` transferring ownership, `release` now just frees the underlying pointer and nulls the `Unique`.\r\n\r\n- `Unique.create` has transformed into a freestanding `unique` function. Regardless of whether or not there is language support for checking uniqueness, a utility function that creates a `Unique`, taking the same arguments as the underlying type's constructor, is extremely useful, as demonstrated by the addition of `make_unique` to C++14.\r\n\r\n- Constructors taking a pointer have been removed. Building a `Unique` from a pointer instead of `unique`  is necessary only for nested types, so we now have the more descriptive `fromNested`.\r\n\r\n- A new method, `get`, returns the underlying pointer, for use in functions and code that do not play a role in the life cycle of the object. Smart pointers are as much about ownership semantics as they are about allocating and freeing memory, and non-owning code should continue to refer to data using a raw pointer or a reference.\r\n\r\nThis pull request is not meant to be merged _prima facie_, but to initiate a dialogue. I strongly believe this is a good step in the right direction and would love to hear commentary from the core devs. Perhaps some of the implementation details need to be hashed out some more, but we can all agree that a stronger showing from the smart pointers in `std.typecons` will only bolster D and Phobos."},"comment":{"url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/comments/92354180","html_url":"https://github.com/D-Programming-Language/phobos/pull/3139#issuecomment-92354180","issue_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3139","id":92354180,"user":{"login":"schuetzm","id":560664,"avatar_url":"https://avatars.githubusercontent.com/u/560664?v=3","gravatar_id":"","url":"https://api.github.com/users/schuetzm","html_url":"https://github.com/schuetzm","followers_url":"https://api.github.com/users/schuetzm/followers","following_url":"https://api.github.com/users/schuetzm/following{/other_user}","gists_url":"https://api.github.com/users/schuetzm/gists{/gist_id}","starred_url":"https://api.github.com/users/schuetzm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/schuetzm/subscriptions","organizations_url":"https://api.github.com/users/schuetzm/orgs","repos_url":"https://api.github.com/users/schuetzm/repos","events_url":"https://api.github.com/users/schuetzm/events{/privacy}","received_events_url":"https://api.github.com/users/schuetzm/received_events","type":"User","site_admin":false},"created_at":"2015-04-13T13:37:14Z","updated_at":"2015-04-13T13:37:14Z","body":"I think an extension of DIP25 (sealed references) is more likely to be the final solution than DIP69; your `return ref` suggestion is therefore the way to go.\r\n\r\nCoincidentally, I dumped my thoughts on unique/isolated into the wiki yesterday:\r\nhttp://wiki.dlang.org/User:Schuetzm/isolated\r\n\r\nI came across an interesting difference between `Unique` and deadalnix' `@isolated` idea: `Unique` is not transitive, but `@isolated` needs to be, otherwise it couldn't be converted to `immutable` or `shared`. Not sure yet how to reconcile the two."}}