[lambda][shared_ptr] Creating a shared_ptr with a custom delete function using a lambda expression
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; };
participants (1)
-
Ryan McConnehey