Boost logo

Boost Users :

Subject: [Boost-users] [lambda] Initializing a std::list of unsigned short points
From: Ryan McConnehey (mccorywork_at_[hidden])
Date: 2009-10-12 00:33:57


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<unsigned short *> 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)));


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