Boost logo

Boost Users :

Subject: Re: [Boost-users] [lambda] how to get rid of the reference argument in lambda functor?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-04-09 10:19:57


AMDG

Pobinger Gerhard Stefan wrote:
> Hi *,
>
> I was desparately trying to compile something like this (VS2008), always getting the error that it cannot convert from int* to int*&.
>
> :boost::shared_ptr<int> c;
> ::boost::lambda::var(c)
> =::boost::lambda::constructor
> <::boost::shared_ptr<int>>()
> (::boost::lambda::new_ptr<int>()()
> )
>

I don't think that you want to evaluate new_ptr<int>() immediately.
Try this (removing namespaces for clarity)
(var(c) = constructor<shared_ptr<int> >(new_ptr<int>()))()

> [This is "short form" for the conventional code
> ::boost::shared_ptr<int>c=::boost::shared_ptr<int>(new int());] (1)
>
> The reason is that all lambda functors take arguments by reference. In this case, make_const in front of shared_ptr did not solve the problem, it causes immediate evaluation of the new_ptr functor...
>
> Is there any way to rewrite this (1) short line of code in boost-lambda?
>

In Christ,
Steven Watanabe


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