> What does `std:unique_ptr` add is not "already trivially possible"?
On its own it does not add much. With its counterparts `shared_ptr` and `weak_ptr`, however, it adds a few things, such as interoperability with `shared_ptr` e.g. via `make_unique`, etc.
>
Why does everyone need to roll their own "generic_cleanup" class when there could be a simple standard-defined one?
Two reasons, I think:
1. There are a lot of ways to do it and the chosen strategy often depends on context, code structure, etc.
2. It's quick and easy to do so.
> And yours is horribly inefficient, as it uses `std::function`.
There's nothing inherently inefficient about std::function, although if you prefer you can substitute `void (* cleanup)` as a pointer type, the idea is identical and the actual implementation of any scope-based cleanup code would end up yielding similar, if not identical, results. If it's performance-critical cleanup code you should probably roll your own anyways, or change resource management strategies in general, but I was just trying to give constructive suggestions, take them or leave them. :)
Jason