Daily bit(e) of C++ | Legacy resources with std::unique_ptr
Daily bit(e) of C++ #85, Wrapping legacy resources with std::unique_ptr
A typical pattern with legacy APIs is for the initializing function to return an opaque pointer that needs to be freed by manually calling a cleanup function.
std::unique_ptr
can serve as a helper here, as it accepts custom deleters. Unfortunately, the interface is not ergonomic, which we can fix by introducing a short helper.
Thanks for this! I was thinking of making SDL value type wrappers using this technique. Is that a good idea?