News for hackers. Stuff that matters.
Re:C++14 and SDL2: Managing Resources by nly on Friday April 18, 2014 @02:59PM (#7610684)
unique_ptr is not really a good solution to this problem. Something like Boost.ScopeExit for short lived resources, or shared_ptr (which stores the deleter using type erasure, meaning you don't need to allow evidence of the deleter to to permeate through your codebase) is a lot easier on the eyes...

    template <typename... Args> inline
    std::shared_ptr<SDL_Window> CreateWindow (Args&&... args) {
        return std::shared_ptr<SDL_Window> {SDL_CreateWindow(std::forward<Args>(args...)),
                                            &SDL_DestroyWindow};
    }

    auto window = CreateWindow ("App Name", SDL_WINDOWPOS_UNDEFINED, 
                                SDL_WINDOWPOS_UNDEFINED, 640, 480, 0);
You know, or someone should write a good quality wrapper like you would just expect for any other language (Python, Ruby, whatever). Many here seem to be blasting C++ when nobody is doing any better without a similar level amount of work elsewhere.
Re:C++14 and SDL2: Managing Resources by lholden on Friday April 18, 2014 @04:04PM (#7611007)
'shared_ptr' can use type erasure because it is a much heavier object. 'unique_ptr' on the other hand is supposed to be a nearly free.

If you wanted a version of your code with unique_ptr, you would create a SDLDelete struct template. The result would be nearly identical except for an additional type parameter (and the new struct).

Then if you wanted to make "CreateWindow" generic for any of SDL's create/delete pairs... you are basically looking at the OP's make_resource code but slightly different. :P Their version just avoids making a new struct.