Boost logo

Boost Users :

From: Nat Goodspeed (ngoodspeed_at_[hidden])
Date: 2007-04-26 10:18:17


> -----Original Message-----
> From: boost-users-bounces_at_[hidden] [mailto:boost-users-
> bounces_at_[hidden]] On Behalf Of pheres
> Sent: Wednesday, April 25, 2007 6:27 PM
> To: boost-users_at_[hidden]
> 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


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