I have the below templated deletor class which I use with unique_ptr to delete C types.
template<typename T, void (*DeletorFunc)(T*)>
struct CTypeDeletor
{
void operator()(T* ptr)
{
DeletorFunc(ptr);
}
};
int main(void)
{
typedef unique_ptr<CType, CTypeDeletor<CType, CType_free>> CTypePtr;
CTypePtr ctype(CType_new());
// ctype will be deleted when we return from main
}
Well, this works as long as CType_free's return type is 'void'. But if the dfree function's return type is not 'void' then I couldn't use the CTypeDeletor.
Is there a way I can make the CTypeDeletor more generic so that I can use free function with any return type?
Aucun commentaire:
Enregistrer un commentaire