@@ -34,4 +34,13 @@ public: | |||
template<typename T, void (*Func)(T *)> | |||
using CPtr = std::unique_ptr<T, CPtrDeleter<T, Func>>; | |||
// Take a function, run it when the object goes out of scope | |||
template<void (*Func)()> | |||
class Deferred: NonCopyable { | |||
public: | |||
Deferred() = default; | |||
~Deferred() { Func(); } | |||
}; | |||
} |
@@ -18,6 +18,7 @@ const char *fragmentSource = R"( | |||
int main() { | |||
SDL_Init(SDL_INIT_VIDEO); | |||
Cygnet::Deferred<SDL_Quit> sdl; | |||
Cygnet::Window win("Hello Triangle", 640, 480); | |||
Cygnet::GlShader vertex(vertexSource, Cygnet::GlShader::Type::VERTEX); | |||
@@ -53,5 +54,5 @@ int main() { | |||
} | |||
exit: | |||
SDL_Quit(); | |||
return EXIT_SUCCESS; | |||
} |