从boost :: shared

编程入门 行业动态 更新时间:2024-10-24 12:26:29
本文介绍了从boost :: shared_ptr的转换到std :: shared_ptr的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我得到的内部使用的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

本文发布于:2023-07-30 00:26:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1244954.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:boost   shared

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!