Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6017019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:04:08+00:00 2026-05-23T03:04:08+00:00

I got a library that internally uses Boost’s version of shared_ptr and exposes only

  • 0

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.

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:04:08+00:00Added an answer on May 23, 2026 at 3:04 am

    Update to an "off the top of my head" answer, almost eleven years later:

    As pointed out in this answer, an implementation is allowed to extend the lifetime the deleter beyond the lifetime of the shared_ptr. For example, until after all weak_ptr instances are also destroyed. This would cause a problem where the presence of weak_ptr instances prevent the destruction of the underlying object, obviously a problem.

    To avoid this, either use the approach in the answer by @Fozi with an explicit call to reset(), or the aliasing constructor approach in the linked answer.

    Original Answer:

    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));
    
    }
    

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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a Palm OS/Garnet 68K application that uses a third-party static library built
I've got a .net 2.0 class library that uses .net remoting to communicate with
I've got some library code that works on a range of .NET runtimes (regular,
I've got a C++ library that lets me write plugins in C++ and then
I've got a managed c++ library that is crashing when a delete statement is
Anyone got a good handle on a barcode scanning library that can be used
I've got a CSV file that I'm processing using the opencsv library. So I
I got a solution that includes 3 different projects, a Class Library, a Web
I have got this error when using Enterprise Library 3.1 May 2007 version. We
I've got a third-party library that generates a ton of warnings, even under /W3.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.