mercredi 5 juillet 2023

RAII using custom deleter of unique_ptr

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

Aucun commentaire:

Enregistrer un commentaire