Boost logo

Boost Users :

Subject: [Boost-users] [shared_ptr] Using a custom delete function that is a class member function
From: Ryan McConnehey (mccorywork_at_[hidden])
Date: 2009-10-09 19:32:20


I have a class that provides a shared_ptr number. At the end of the
number's life cycle it should be placed back on a list of available
numbers. The shared_ptr's custom deleter function looks like what I
need. I'm able to get a free function to compile as the deleter just
fine. In trying to use a class member function as the custom deleter
I've run into compile errors. I'm not sure where I'm going wrong. I
know the custom deleter need to be copy constructible and I'm probably
breaking some assumed requirement. Any help on what I'm doing wrong
would be appreciated.

Ryan

class CTNGenerator {
public:
CTNGenerator(void) {
  m_AvailableCTNs.resize(20);
  unsigned short startValue = 15;

  for (ctns::iterator itor = m_AvailableCTNs.begin(); itor !=
m_AvailableCTNs.end(); ++itor) {
    //This compiles fine.
    boost::bind(boost::mem_fun(&CTNGenerator::makeCTNAvailable), this);
    //Placing the call as the custom delete function doesn't compile.
    *itor = bus(new unsigned short(startValue++),
boost::bind(boost::mem_fun(&CTNGenerator::makeCTNAvailable, this)));
  }
}

private:
void CTNGenerator::makeCTNAvailable(unsigned short * ctn) {
   m_AvailableCTNs.push_back(boost::shared_ptr<unsigned short>(ctn));
}

private:
  typedef boost::shared_ptr<unsigned short> bus;
  typedef std::list<bus> ctns;
  ctns
m_AvailableCTNs;
};


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net