3 ms·
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.
by vlovich123 5y ago
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.
- gerdesj 5y agoNo it isn't. What is a downside is you could not be arsed to explain why (blah means blah) to a reasonably intelligent audience.
- ridiculous_fish 5y agoYou 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.
- deleted 5y ago[deleted]
- cma 5y agoThat 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.
- leni536 5y agoYou have to do that anyway, unique_ptr only makes forgetting that a compile error.