我得到的内部使用的shared_ptr 的Boost的版本,并公开只有那些库。我的应用程序,我想使用的std :: shared_ptr的尽可能虽然。可悲的是,这两种类型之间没有直接转换,裁判计数东西是依赖于实现的。
I got a library that internally uses Boost's version of shared_ptr and exposes only those. For my application, I'd like to use std::shared_ptr whenever possible though. Sadly, there is no direct conversion between the two types, as the ref counting stuff is implementation dependent.
有没有办法同时拥有的boost :: shared_ptr的和的std :: shared_ptr的共享相同裁判计数对象?或至少来自Boost版偷裁判计数,只有让STDLIB版本照顾它?
Is there any way to have both a boost::shared_ptr and a std::shared_ptr share the same ref-count-object? Or at least steal the ref-count from the Boost version and only let the stdlib version take care of it?
推荐答案您可以通过使用析构函数随身携带的基准进行了boost :: shared_ptr的内部的std :: shared_ptr的:
You can carry the boost::shared_ptr "inside" the std::shared_ptr by using the destructor to carry the reference around:
template<typename T> void do_release(typename boost::shared_ptr<T> const&, T*) { } template<typename T> typename std::shared_ptr<T> to_std(typename boost::shared_ptr<T> const& p) { return std::shared_ptr<T>( p.get(), boost::bind(&do_release<T>, p, _1)); }唯一的真正原因,要做到这一点,如果你有一堆code的一个期望的std :: shared_ptr的&LT; T&GT;
更多推荐
从boost :: shared
发布评论