{"action":"created","issue":{"url":"https://api.github.com/repos/foonathan/memory/issues/28","repository_url":"https://api.github.com/repos/foonathan/memory","labels_url":"https://api.github.com/repos/foonathan/memory/issues/28/labels{/name}","comments_url":"https://api.github.com/repos/foonathan/memory/issues/28/comments","events_url":"https://api.github.com/repos/foonathan/memory/issues/28/events","html_url":"https://github.com/foonathan/memory/issues/28","id":304948327,"number":28,"title":"nullptr as unique_ptr with Deleter ","user":{"login":"gabyx","id":647437,"avatar_url":"https://avatars0.githubusercontent.com/u/647437?v=4","gravatar_id":"","url":"https://api.github.com/users/gabyx","html_url":"https://github.com/gabyx","followers_url":"https://api.github.com/users/gabyx/followers","following_url":"https://api.github.com/users/gabyx/following{/other_user}","gists_url":"https://api.github.com/users/gabyx/gists{/gist_id}","starred_url":"https://api.github.com/users/gabyx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gabyx/subscriptions","organizations_url":"https://api.github.com/users/gabyx/orgs","repos_url":"https://api.github.com/users/gabyx/repos","events_url":"https://api.github.com/users/gabyx/events{/privacy}","received_events_url":"https://api.github.com/users/gabyx/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2018-03-13T21:49:37Z","updated_at":"2018-03-14T21:17:00Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"I have the following problem: I have a class `BinaryBuffer` which should have a default Ctor:\r\n```cpp\r\nusing Deleter     = foonathan::memory::allocator_deleter<uint8_t[], RawAllocator>;\r\nusing BufferPtr  = std::unique_ptr<uint8_t[], Deleter>;\r\n\r\n//! Constructor for an empty buffer!\r\n    BinaryBuffer(std::shared_ptr<RawAllocator> allocator)\r\n        : m_allocator(allocator)\r\n        , m_data(nullptr, Deleter{foonathan::memory::make_allocator_reference(*allocator), 0})\r\n    {}\r\n```\r\nIt takes a RawAllocator which it keeps as reference (`m_allocator`). The data `m_data` is of type `BufferPtr`. My problem I am facing is, that I need a valid allocator smart pointer (not nullptr) such that I can setup the Deleter, even if the pointer is actually `nullptr`. Is there a way of having a default CTOR where I set the `m_data` member to nullptr, with an invalid deleter.\r\nIs there such a wrapper like `make_allocator_pointer(allocator.get())` which wraps a pointer to the allocator internally which I can default to `nullptr`. Or can this be achieved similarly?\r\n"},"comment":{"url":"https://api.github.com/repos/foonathan/memory/issues/comments/373177670","html_url":"https://github.com/foonathan/memory/issues/28#issuecomment-373177670","issue_url":"https://api.github.com/repos/foonathan/memory/issues/28","id":373177670,"user":{"login":"gabyx","id":647437,"avatar_url":"https://avatars0.githubusercontent.com/u/647437?v=4","gravatar_id":"","url":"https://api.github.com/users/gabyx","html_url":"https://github.com/gabyx","followers_url":"https://api.github.com/users/gabyx/followers","following_url":"https://api.github.com/users/gabyx/following{/other_user}","gists_url":"https://api.github.com/users/gabyx/gists{/gist_id}","starred_url":"https://api.github.com/users/gabyx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gabyx/subscriptions","organizations_url":"https://api.github.com/users/gabyx/orgs","repos_url":"https://api.github.com/users/gabyx/repos","events_url":"https://api.github.com/users/gabyx/events{/privacy}","received_events_url":"https://api.github.com/users/gabyx/received_events","type":"User","site_admin":false},"created_at":"2018-03-14T21:17:00Z","updated_at":"2018-03-14T21:17:00Z","author_association":"CONTRIBUTOR","body":"Some thoughts: The standart says: http://eel.is/c++draft/unique.ptr#single.dtor\r\n> Effects: If get() == nullptr there are no effects. Otherwise get_­deleter()(get()).\r\nSo the deleter is not called if it is nullptr, so I suppose, we can store an empty deleter in it."}}
{"actor":{"display_login":"gabyx"}}