One of my favourite things about Go is the
defer statement. The
defer statement pushes a function call onto a list; the list of saved calls in called when the function returns.
Imitating this is C++ is impossible. Instead of calling when the function calls, you can call at the end of scope; this is a better approach for C++. This is similar to how D has scope(exit).