
Robert Caldecott wrote:
OK, I'm a bit of a boost noob. I have a container of std::wstring's and I want to use a lambda expression in a for_each loop to pass each string to a WinAPI function - however, I need access to the c_str() method, and this is giving me a problem.
For example, if I want to use the DeleteFile WinAPI call, I want to write something like:
std::vectorstd::wstring v; ... for_each(v.begin(), v.end(), ::DeleteFile(_1));
But the above won't work as I need to pass the 'C' string to ::DeleteFile.
So, I really want to be able to do something like this:
for_each(v.begin(), v.end(), ::DeleteFile(_1.c_str()));
Any ideas how I can access a member function (like c_str()) using a lambda placeholder?
You need to use the binders of lambda, like this: for_each(v.begin(), v.end(), ::DeleteFile(bind(&std::wstring::c_str, _1))); Sebastian Redl