|
Boost : |
From: JeanHeyd Meneide (phdofthehouse_at_[hidden])
Date: 2019-06-29 19:33:30
Dear Bagaskoro Kang,
I apologize, I thought my previous message got the example through to
you, but it seems like it did not. Here is the example using out_ptr to do
what you describe:
struct SizedDeleter {
size_t size = 0;
void operator()(Interface* obj) const {
DeleteBusInterface(obj, size);
}
};
using bop = boost::out_ptr;
size_t& size_ref = p_obj.get_deleter().size;
std::unique_ptr<Interface, SizedDeleter> obj;int ret =
CreateBusInterface(..., bop::out_ptr(obj), &size_ref);if (ret != 0) {
throw std::runtime_error("deep sadness");
}/* use obj ...*/
Similarly, for posix_memalign:
using bop = boost::out_ptr;
std::unique_ptr<Numf, DoFree> upNumf;/* some work... */int ret =
posix_memalign(bop::out_ptr<void*>(upNumf), 64, nNumf);if (ret != 0) {
throw std::runtime_error("something went wrong and posix_memalign
failed!");
}
I hope that helps.
Sincerely,
JeanHeyd
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk