I am trying to map a third-party API using a unique unique_ptr decoder. The problem is that the API is like this:
x *x_alloc_x(void);
void x_free_x(x **p);
The API wants me to provide a pointer to a pointer so that it sets to NULL. I wrote my deleter functor as a translator-pointer, which I convert to a pointer to a pointer using the & operator.
struct XDeleter {
void operator(x *&p) { x_free_x(&p); }
};
This works with GCC 4.6, but is it really allowed by the standard? If not, is there a standard way to map this API to a deleter?
source
share