I am dealing with C types which have a new_
and free_
methods associated.
The type signature of new_
may vary, but the free_
is always a void free_something(something*);
Currently, I am declaring my unique_ptr
s this way, which seems overly verbose:
std::unique_ptr<qdr_link_t, decltype(&free_qdr_link_t)> link{new_qdr_link_t(), free_qdr_link_t};
Can I do this with less ceremony, somehow? I saw a neat solution for a situation when my deallocator is the std::free()
function, at https://stackoverflow.com/a/43626234/1047788. I tried to create a version where I could parameterize the deallocator, but I got nowhere with it.
The best I could think of was to create a macro from the above declaration.