I want to use boost::log
at some point, but I cannot pass a std::shared_ptr
as a parameter, because the compiler (VS2010) cannot convert it into a
You could do it like this:
template
boost::shared_ptr make_shared_ptr(std::shared_ptr& ptr)
{
return boost::shared_ptr(ptr.get(), [ptr](T*) mutable {ptr.reset();});
}
template
std::shared_ptr make_shared_ptr(boost::shared_ptr& ptr)
{
return std::shared_ptr(ptr.get(), [ptr](T*) mutable {ptr.reset();});
}
EDIT: Note that this does not work with weak references to the source ptr. So be careful with those!