 
            
            
            
            
                30 Nov
                
                    2023
                
            
            
                30 Nov
                
                '23
                
            
            
            
        
    
                5:02 p.m.
            
        Andrey Semashev wrote:
I think a similar utility would be more useful in form of a class template, for example:
resource<HANDLE, INVALID_HANDLE_VALUE, ::CloseHandle> windows_handle; resource<SDL_Window*, nullptr, ::SDL_DestroyWindow> sdl_window_handle;
That's template<class R, auto Def, auto Del> class resource;
This would also prohibit resource types with non-constexpr constructors, as well as non-default-constructible resources. I don't like this tradeoff.
It doesn't. The two operations required from R are construction from Def and comparing to Def. https://godbolt.org/z/h7z3qGzvs Note that the type of Def doesn't have to be R.