
AMDG Ryan McConnehey wrote:
In my project I'm trying to initialize a std::list of unsigned short pointers. I've created a couple of simple hand written loops but would like to convert them to use std::for_each. I've been unsuccessful in the past getting boost::lambda to work with std container of pointers. In the lambda documentation I know that new_ptr and delete_ptr are need in creating and destroying pointers in lambda functions. I've provided the hand written loop that does work and the "attempted" conversion to std::for_each. Any help on the correct implementation for the lambda values would be appreciated.
Ryan
typedef std::list
ml; for (ml::iterator itor = m_list.begin(); itor != m_list.end(); ++itor, startValue++) { *itor = new unsigned short(startValue); } for (ml::iterator itor = m_list.begin(); itor != m_list.end(); ++itor) { delete *itor; }
std::for_each(m_list.begin(), m_list.end(), *(bl::_1) = bl::new_ptr<unsigned short>()(bl::var(startValue)++) ); std::for_each(m_list.begin(), m_list.end(), boost::lambda::delete_ptr(*(boost::lambda::_1)));
Use bind. std::generate(m_list.begin(), m_list.end(), bl::bind(bl::new_ptr<unsigned short>(), bl::var(startValue)++); std::for_each(m_list.begin(), m_list.end(), bl::bind(bl::delete_ptr(), bl::_1)); In Christ, Steven Watanabe