Facebook&#x27;s Folly library implements something similar: <a href="https:&#x2F;&#x2F;github.com&#x2F;facebook&#x2F;folly&#x2F;blob&#x2F;master&#x2F;folly&#x2F;ScopeGuard.h" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;facebook&#x2F;folly&#x2F;blob&#x2F;master&#x2F;folly&#x2F;ScopeGua...</a><p>It provides some macros to make it easier to use, e.g.<p><pre><code>  SCOPE_EXIT {
    cleanup();
    more_cleanup();
    if (needs_even_more_cleanup)
      even_more_cleanup();
  };</code></pre>