I'm trying to use a unique ptr in the following scenario:
MyClass *pMC = NULL;
if ( !MyCustomAlloc(void ** (&pMC), sizeof(MyClass) )
{
return false;
}
// do things
if (something else fails)
{
MyCustomDelete(pMC);
return false;
}
Now, what I'm trying to do is have convert this to a unique ptr so that the MyCustomDelete doesn't need to be called explicitly.
What I don't get is how I can retain the above structure and still return the appropriate values.
unique_ptr<MyClass, void (*)(void**, size_t)> pMC( <b>Not Sure What Goes Here</b> , MyCustomDelete);
- If I put MyCustomAlloc as the 1st arg, how will it's failure be detected?
Or if I do the following then pMC will be initialized to NULL, but how can the custom deleter be set?
unique_ptr<MyClass, void (*)(void**, size_t)> pMC;
Can I do something like
pMC.set(MyCustomDelter)
?