• <legend id='5mDdZ'><style id='5mDdZ'><dir id='5mDdZ'><q id='5mDdZ'></q></dir></style></legend>

        <tfoot id='5mDdZ'></tfoot>
          <bdo id='5mDdZ'></bdo><ul id='5mDdZ'></ul>

      1. <i id='5mDdZ'><tr id='5mDdZ'><dt id='5mDdZ'><q id='5mDdZ'><span id='5mDdZ'><b id='5mDdZ'><form id='5mDdZ'><ins id='5mDdZ'></ins><ul id='5mDdZ'></ul><sub id='5mDdZ'></sub></form><legend id='5mDdZ'></legend><bdo id='5mDdZ'><pre id='5mDdZ'><center id='5mDdZ'></center></pre></bdo></b><th id='5mDdZ'></th></span></q></dt></tr></i><div id='5mDdZ'><tfoot id='5mDdZ'></tfoot><dl id='5mDdZ'><fieldset id='5mDdZ'></fieldset></dl></div>

        <small id='5mDdZ'></small><noframes id='5mDdZ'>

        从 boost::shared_ptr 到 std::shared_ptr 的转换?

        时间:2023-07-20
      2. <tfoot id='1t77V'></tfoot>

          <small id='1t77V'></small><noframes id='1t77V'>

          <i id='1t77V'><tr id='1t77V'><dt id='1t77V'><q id='1t77V'><span id='1t77V'><b id='1t77V'><form id='1t77V'><ins id='1t77V'></ins><ul id='1t77V'></ul><sub id='1t77V'></sub></form><legend id='1t77V'></legend><bdo id='1t77V'><pre id='1t77V'><center id='1t77V'></center></pre></bdo></b><th id='1t77V'></th></span></q></dt></tr></i><div id='1t77V'><tfoot id='1t77V'></tfoot><dl id='1t77V'><fieldset id='1t77V'></fieldset></dl></div>

            1. <legend id='1t77V'><style id='1t77V'><dir id='1t77V'><q id='1t77V'></q></dir></style></legend>
                <tbody id='1t77V'></tbody>

                  <bdo id='1t77V'></bdo><ul id='1t77V'></ul>

                  本文介绍了从 boost::shared_ptr 到 std::shared_ptr 的转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个库,它在内部使用 Boost 的 shared_ptr 版本,并且只公开那些.对于我的应用程序,我想尽可能使用 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_ptrstd::shared_ptr 共享同一个引用计数对象?或者至少从 Boost 版本中窃取 ref-count 而只让 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));
                  
                  }
                  

                  这样做的唯一真正原因是,如果您有一堆需要 std::shared_ptr<T> 的代码.

                  The only real reason to do this is if you have a bunch of code that expects std::shared_ptr<T>.

                  这篇关于从 boost::shared_ptr 到 std::shared_ptr 的转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何启用父代和派生的_shared_from_this 下一篇:如何使用格式 dd/mm/yyyy 格式化日期时间对象?

                  相关文章

                  <i id='aMcAR'><tr id='aMcAR'><dt id='aMcAR'><q id='aMcAR'><span id='aMcAR'><b id='aMcAR'><form id='aMcAR'><ins id='aMcAR'></ins><ul id='aMcAR'></ul><sub id='aMcAR'></sub></form><legend id='aMcAR'></legend><bdo id='aMcAR'><pre id='aMcAR'><center id='aMcAR'></center></pre></bdo></b><th id='aMcAR'></th></span></q></dt></tr></i><div id='aMcAR'><tfoot id='aMcAR'></tfoot><dl id='aMcAR'><fieldset id='aMcAR'></fieldset></dl></div>
                    <bdo id='aMcAR'></bdo><ul id='aMcAR'></ul>

                    <legend id='aMcAR'><style id='aMcAR'><dir id='aMcAR'><q id='aMcAR'></q></dir></style></legend>

                  1. <tfoot id='aMcAR'></tfoot>

                    <small id='aMcAR'></small><noframes id='aMcAR'>