|
Boost Users : |
From: Rob Caldecott (robert.caldecott_at_[hidden])
Date: 2006-03-11 12:36:20
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_at_[hidden]> wrote in message
news:4412FDC4.2020002_at_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
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