Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > boost lambda binding question

Reply
Thread Tools

boost lambda binding question

 
 
baliga@gmail.com
Guest
Posts: n/a
 
      01-26-2007
(std::cout << _1 << _2)("hello", 10);

This does not work. If 2 parameters are string, it works. If any one or
both parameters are integers, it does not work.

But If I change it to

boost::function<void(int, int)> f = std::cout << _1 << _2;
f(10, 10);

it works.

Question is why the first one does not work when one of the parameter
is integer.

Thanx,
-- baliga

http://baliga.blogdns.com/blog

 
Reply With Quote
 
 
 
 
shunsuke
Guest
Posts: n/a
 
      01-26-2007
On Jan 26, 9:50 am, (E-Mail Removed) wrote:
> (std::cout << _1 << _2)("hello", 10);
>
> This does not work. If 2 parameters are string, it works. If any one or
> both parameters are integers, it does not work.
>
> But If I change it to
>
> boost::function<void(int, int)> f = std::cout << _1 << _2;
> f(10, 10);
>
> it works.
>
> Question is why the first one does not work when one of the parameter
> is integer.


Hi,

Lambda Functor can't accept a non-const rvalue(temporary).
See..
http://www.boost.org/doc/html/lambda...tual_arguments
http://std.dkuug.dk/jtc1/sc22/wg21/d...2002/n1385.htm

Thus,
(std::cout << _1 << _2)("hello", make_const(10));
works fine.

--
Shunsuke Sogame

 
Reply With Quote
 
 
 
 
baliga@gmail.com
Guest
Posts: n/a
 
      01-26-2007


On Jan 25, 8:25 pm, "shunsuke" <(E-Mail Removed)> wrote:
> On Jan 26, 9:50 am, (E-Mail Removed) wrote:
>
> > (std::cout << _1 << _2)("hello", 10);

>
> > This does not work. If 2 parameters are string, it works. If any one or
> > both parameters are integers, it does not work.

>
> > But If I change it to

>
> > boost::function<void(int, int)> f = std::cout << _1 << _2;
> > f(10, 10);

>
> > it works.

>
> > Question is why the first one does not work when one of the parameter
> > is integer.Hi,

>
> Lambda Functor can't accept a non-const rvalue(temporary).
> See..http://www.boost.org/doc/html/lambda...2002/n1385.htm
>
> Thus,
> (std::cout << _1 << _2)("hello", make_const(10));
> works fine.
>
> --
> Shunsuke Sogame


Thanx for the solution. But I still have one question. why
make_const("hello") is not required for the string or is there any
implicit conversion going on within boost?

 
Reply With Quote
 
shunsuke
Guest
Posts: n/a
 
      01-27-2007
"reference to array" kicks in.
The reference seems passed to 'operator<<' as is.
Then, the 'operator<<' overload of 'char const*' is selected, AFAIK.


Regards,

--
Shunsuke Sogame


On Jan 27, 4:08 am, (E-Mail Removed) wrote:
> On Jan 25, 8:25 pm, "shunsuke" <(E-Mail Removed)> wrote:
>
>
>
>
>
> > On Jan 26, 9:50 am, (E-Mail Removed) wrote:

>
> > > (std::cout << _1 << _2)("hello", 10);

>
> > > This does not work. If 2 parameters are string, it works. If any one or
> > > both parameters are integers, it does not work.

>
> > > But If I change it to

>
> > > boost::function<void(int, int)> f = std::cout << _1 << _2;
> > > f(10, 10);

>
> > > it works.

>
> > > Question is why the first one does not work when one of the parameter
> > > is integer.Hi,

>
> > Lambda Functor can't accept a non-const rvalue(temporary).
> > See..http://www.boost.org/doc/html/lambda...#lambda.rvalue...

>
> > Thus,
> > (std::cout << _1 << _2)("hello", make_const(10));
> > works fine.

>
> > --
> > Shunsuke SogameThanx for the solution. But I still have one question. why

> make_const("hello") is not required for the string or is there any
> implicit conversion going on within boost?- Hide quoted text -- Show quoted text -


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
lambda vs non-lambda proc Steve Dogers Ruby 1 03-30-2009 10:11 PM
confused by boost::bind & boost::lambda::bind XHengDF@gmail.com C++ 0 05-29-2007 04:37 AM
Boost::any and boost::lambda with std::find_if Misiu C++ 3 01-31-2007 05:46 PM
Problems mixing boost::lambda::bind and boost::shared_ptr.. Toby Bradshaw C++ 6 06-02-2006 04:12 PM
Re: Lambda as declarative idiom (was RE: what is lambda used for inreal code?) Roman Suzi Python 13 01-07-2005 09:33 PM



Advertisments