|
Boost Users : |
Subject: [Boost-users] [lambda][shared_ptr] Creating a shared_ptr with a custom delete function using a lambda expression
From: Ryan McConnehey (mccorywork_at_[hidden])
Date: 2009-10-07 20:49:17
I have a class that maintains a list of available numbers. The user
will ask for a number and receive a shared_ptr with a value. Once the
user is done with the number it will be put back on the list of
available numbers. I'm trying to initialize the list with numbers and a
custom delete function for the shared_ptr to be return to the list. Any
help would be appropriated in how to get the lambda and custom delete
function to work.
Ryan
class CTNGenerator {
public:
CTNGenerator(void) {
m_AvailableCTNs.resize(20);
unsigned short startValue = 15;
typedef boost::shared_ptr<unsigned short> bus;
//The lambda function isn't compiling with how it's currently written.
std::for_each(m_AvailableCTNs.begin(), m_AvailableCTNs.end(), _1 =
bus(new bus(var(startValue++)), &makeCTNAvailable));
}
private:
void CTNGenerator::makeCTNAvailable(unsigned short * ctn) {
m_AvailableCTNs.push_back(boost::shared_ptr<unsigned short>(ctn));
}
private:
std::list< boost::shared_ptr<unsigned short> > 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