|
|
|
|
|
by michaelrmmiller
4437 days ago
|
|
The other downside to their approach is that you have to pass the function into the constructor every time you construct an object. A similar alternative would be to template the deleter on the type of the function and then a specific function. This way you can wrap functions with non-void return values. Something like: template<typename FuncType, FuncType& F> struct deleter { ... };
using unique_cptr = std::unique_ptr<void, deleter<decltype(free), free>>;
The other cool thing I learned recently is you can actually use the custom deleter to override the wrapped type by typedef'ing pointer in your deleter class. You can use this to wrap C-style file descriptors in a unique_ptr. |
|
That's why the suggest a make_window function at the bottom of the post. The end-user just calls:
The optimizer should inline all the extra wrappers away, so there's no overhead for doing as the article suggests.