You can create a functor with several overloaded implementations of operator() , each of which calls the correct destruction function for the corresponding type of argument.
struct sdl_deleter { void operator()(SDL_Window *p) const { SDL_DestroyWindow(p); } void operator()(SDL_Renderer *p) const { SDL_DestroyRenderer(p); } void operator()(SDL_Texture *p) const { SDL_DestroyTexture(p); } };
Pass this as deleter in unique_ptr , and you could write wrapper functions, if you want, create unique_ptr s
unique_ptr<SDL_Window, sdl_deleter> create_window(char const *title, int x, int y, int w, int h, Uint32 flags) { return unique_ptr<SDL_Window, sdl_deleter>( SDL_CreateWindow(title, x, y, w, h, flags), sdl_deleter()); }
Praetorian
source share