C++ scope guard implementation