R
rammel
hi,
can't I call member functions from an placeholder of a boost-like
lambda expression?
look on the example below please:
-----------------------------------------------------------
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
#include <boost/lambda/lambda.hpp>
using namespace std;
using namespace boost::lambda;
int main(int argc, char **argv)
{
// this works:
vector<string> v1(10);
fill(v1.begin(), v1.end(), "haha");
for_each(v1.begin(), v1.end(), cout << _1 << " ");
cout << endl;
// this works, too:
vector<string*> v2(10);
fill(v2.begin(), v2.end(), new string("hehe"));
for_each(v2.begin(), v2.end(), cout << *_1 << " ");
cout << endl;
// this doesn't:
vector<string> v3(10);
fill(v3.begin(), v3.end(), "hoho");
for_each(v3.begin(), v3.end(), cout << _1->c_str() << " ");
// error: base operand of '->' has non-pointer type 'const
cout << v3.begin()->c_str() << endl; // this works, just to be
sure
cout << endl;
can't I call member functions from an placeholder of a boost-like
lambda expression?
look on the example below please:
-----------------------------------------------------------
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
#include <boost/lambda/lambda.hpp>
using namespace std;
using namespace boost::lambda;
int main(int argc, char **argv)
{
// this works:
vector<string> v1(10);
fill(v1.begin(), v1.end(), "haha");
for_each(v1.begin(), v1.end(), cout << _1 << " ");
cout << endl;
// this works, too:
vector<string*> v2(10);
fill(v2.begin(), v2.end(), new string("hehe"));
for_each(v2.begin(), v2.end(), cout << *_1 << " ");
cout << endl;
// this doesn't:
vector<string> v3(10);
fill(v3.begin(), v3.end(), "hoho");
for_each(v3.begin(), v3.end(), cout << _1->c_str() << " ");
// error: base operand of '->' has non-pointer type 'const
// boost::lambda::lambda_functor said:
cout << v3.begin()->c_str() << endl; // this works, just to be
sure
cout << endl;