Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The downside of unique_ptr used this way is that you have to define ~C in the same translation unit that the declaration of C::Impl lives.


You can use a custom deleter, e.g.

    struct deleter_t { void operator()(impl_t *); };
    using impl_unique_ptr_t = std::unique_ptr<impl_t, deleter_t>;

You can place the implementation of the deleter alongside the impl.


That breaks make_unique. Maybe unique_ptr inside an std::any? Error-prone casting, but managed lifetime. Though make_unique is maybe obsolete now that parameter evaluation order is better defined.


You have to do that anyway, unique_ptr only makes forgetting that a compile error.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: