[BLL] Right usage of he placeholder _1 ?

Hello, I've two problems so far with a simple for_each: 1. vector<string*> v2(10); fill(v2.begin(), v2.end(), new string("hehe")); for_each(v2.begin(), v2.end(), cout << *_1 << " "); // works for_each(v2.begin(), v2.end(), delete _1 ); // error // error: type ‘const struct // boost::lambda::lambda_functor<boost::lambda::placeholder<1> // >’ argument given to ‘delete’, expected pointer Shouldn't the placeholder _1 actually become a (string-)pointer as it obviously does in the expression above ( cout << *_1 << " " )? 2. Is it possible to call member functions from an placeholder of a boost-like lambda expression? vector<string> v3(10); fill(v3.begin(), v3.end(), "hoho"); for_each(v3.begin(), v3.end(), cout << _1->c_str() << " "); // error // error: base operand of ‘->’ has non-pointer type ‘const // boost::lambda::lambda_functor<boost::lambda::placeholder<1> >’ Thank you for any input!

-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users- bounces@lists.boost.org] On Behalf Of pheres Sent: Wednesday, April 25, 2007 6:27 PM To: boost-users@lists.boost.org Subject: [Boost-users] [BLL] Right usage of he placeholder _1 ?
1.
vector<string*> v2(10); fill(v2.begin(), v2.end(), new string("hehe")); for_each(v2.begin(), v2.end(), cout << *_1 << " "); // works for_each(v2.begin(), v2.end(), delete _1 ); // error // error: type 'const struct // boost::lambda::lambda_functor<boost::lambda::placeholder<1> // >' argument given to 'delete', expected pointer
Shouldn't the placeholder _1 actually become a (string-)pointer as it obviously does in the expression above ( cout << *_1 << " " )?
[Nat] http://boost.org/doc/html/lambda/le_in_details.html#lambda.construction_ and_destruction
2.
Is it possible to call member functions from an placeholder of a boost- like lambda expression?
vector<string> v3(10); fill(v3.begin(), v3.end(), "hoho"); for_each(v3.begin(), v3.end(), cout << _1->c_str() << " "); // error // error: base operand of '->' has non-pointer type 'const // boost::lambda::lambda_functor<boost::lambda::placeholder<1> >'
[Nat] http://boost.org/doc/html/lambda/le_in_details.html#lambda.operator_expr essions "For some operators, the requirements on return types prevent them to be overloaded to create lambda functors. These operators are ->., ->, new, new[], delete, delete[] and ?: (the conditional operator)." For that you'd use bind(): http://boost.org/doc/html/lambda/le_in_details.html#lambda.bind_expressi ons
participants (2)
-
Nat Goodspeed
-
pheres