I want to do automatic cleanup using std::unique_ptr but to initialize the unique_ptr I need an address to point to. How can I avoid the noUse variable?
bool noUse;
auto deleter = [](bool *){ DESTROY_SOMETHING };
std::unique_ptr<bool, decltype(deleter)> upp(&noUse, deleter); // I want to avoid the usage of this extra noUse variable
START_SOMETHING
//COMPLEX IF ELSE RETURN LOGIC
**UPDATE: ** I finally resorted to this code. Thanks everyone for quick responses.
auto deleter = [](void *){ DESTROY_SOMETHING };
std::unique_ptr<void, decltype(deleter)> upp(nullptr, deleter);
if(enabled)
{
//START_SOMETHING
upp.reset(reinterpret_cast<void *>&upp);
}
//COMPLEX IF ELSE RETURN LOGIC