Add intrusive_ptr<>::detach()

This provides a way to escape from automatic reference counting, and taking
manual control of the reference.  Useful when interfacing to a C API that
expects a pointer with an elevated reference count.

Similar to std::unique_ptr<>::release().
This commit is contained in:
Avi Kivity
2013-12-26 17:47:28 +02:00
committed by Peter Dimov
parent d7fa365843
commit 73153d5797
3 changed files with 31 additions and 0 deletions
+7
View File
@@ -330,6 +330,13 @@ void test()
BOOST_TEST(get_pointer(px) == px.get());
}
{
boost::intrusive_ptr<X> px(new X);
X* detached = px.detach();
BOOST_TEST(detached->use_count() == 1);
delete detached;
}
}
} // namespace n_access