I simply want to use the deleter feature of a shared_ptr without using the shared_ptr part. As in, I want to call a function when the shared_ptr goes out of scope and the deleter doesn't need any pointer passed to it.
I have this but it's cheezy.
shared_ptr<int> x(new int, [&](int *me) { delete me; CloseResource(); });
Is there a way to not associate any pointer with the shared_ptr?
Update: as per many suggestions, the unique_ptr way would look like this:
unique_ptr<int, std::function<void(int*)>> x(new int, [&](int *me) {delete me; CloseResource();});
Which frankly looks worse than the shared_ptr version, as much 'better' as it is.
Update: for those who like using this simple scope closing function caller I made it a bit simpler, you don't even need to allocate or free an object:
shared_ptr<int> x(NULL, [&](int *) { CloseResource(); });