
Thanks Sebastian, but I am still struggling to make this work. I now get the following error: "error C2664: 'DeleteFileW' : cannot convert parameter 1 from 'const boost::lambda::lambda_functor<T>' to 'LPCWSTR'" A small sample: #include <windows.h> #include <string> #include <vector> #include <algorithm> #include <boost/lambda/lambda.hpp> #include <boost/lambda/bind.hpp> int _tmain(int argc, _TCHAR* argv[]) { using namespace std; using namespace boost; using namespace boost::lambda; vector<wstring> v; v.push_back(L"test.txt"); for_each(v.begin(), v.end(), ::DeleteFileW(bind(&wstring::c_str, _1))); return 0; } Any ideas? "Sebastian Redl" <sebastian.redl@getdesigned.at> wrote in message news:4412FDC4.2020002@getdesigned.at...
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::vector<std::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