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

  • Home
  • SEARCH
  • 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 4032872
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:46:33+00:00 2026-05-20T11:46:33+00:00

I have a container of shared_ptr s and I hand these objects off to

  • 0

I have a container of shared_ptrs and I hand these objects off to a windows API and I get a callback later with the raw ptr. I want to locate the right shared_ptr after the fact. Can this be done with shared_ptr cleanly? (without using shared_from_this()).

very basic example:

class CFoo
{
};
typedef std::shared_ptr<CFoo> CFooPtr;
typedef std::set<CFooPtr> CFooSet;

extern CFooSet m_gSet;
void SomeWindowsCallBack(CFoo* pRawPtr)
{
  m_gSet.erase(pRawPtr);
}

I know that this can be done with intrusive_ptr very easily but I am curious if there is a way with shared_ptr. Aka I am looking for the container to accept the RawPtr and the shared_ptr for locating the shared_ptr item. The issue is that I can’t implicitly cast the CFoo* into the shared_ptr (for reasons I do understand).

I was thinking I could do

m_gSet.erase(shared_ptr<CFoo>(pRawPtr, _do_not_delete_deleter))

but I have not tried that yet and it seems dangerous/ugly. Is there another way or am I basically looking for intrusive_ptr? Thanks

  • 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-20T11:46:34+00:00Added an answer on May 20, 2026 at 11:46 am

    Why not the obvious way? Iterate through the container, and

    if(iterator->get() == rawPointer)
       container.erase(iterator)
    

    Edit: To utilize O(logN) lookup you can do what you want (that is, create a shared_ptr with no_op deleter). It may be ugly, but it’s not dangerous

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

Sidebar

Related Questions

I have these container objects (let's call them Container) in a list. Each of
I have a container of smart pointers to mutable objects. I have to write
I have a container div with a fixed width and height , with overflow:
I have a container div that holds two internal divs; both should take 100%
I have a container filled with pairs. I want to iterate in it using
I have a container element which I need to resize as its contents change.
I have a container of custom controls each of which have 2 controls in
Let's say I have a container (std::vector) of pointers used by a multi-threaded application.
I have a div container and have defined its style as follows: div#tbl-container {
I have a function which searches an STL container then returns the iterator when

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.