Boost logo

Boost Users :

Subject: Re: [Boost-users] [lambda][phoenix] make lambda/phoenix play well with std::complex, imag, real, abs, etc.
From: Joel de Guzman (joel_at_[hidden])
Date: 2010-06-07 03:52:50


On 6/7/10 3:42 PM, Alfredo Correa wrote:
> On Sun, Jun 6, 2010 at 4:41 PM, Joel de Guzman
> <joel_at_[hidden]> wrote:
>> Is there a reason why you are not using plain phoenix::function(s)
>> for this?
>
> good point, I am still phoenix-challenged I guess. I got driven by the
> "Composite" example in the manual.
> This is the alternative implementation using phoenix::function:
>
> namespace boost{namespace phoenix{
> struct real_impl{
> template<typename Arg> struct result{
> typedef double type; //can be generalized
> };
> template<typename Arg>
> typename result<Arg>::type
> operator()(Arg z) const{
> return real(z);
> }
> };
> function<real_impl> real_; // "real" as name doesn't work
> }}
> int main(){
> std::complex<double> z(1.,2.);
> cout<< real_(arg1)(z)<<endl;
> return 0;
> }
>
> which works.
> ...But there is a problem it seem that I can not call "real_" as
> "real", so the resulting syntax is degraded.
> (Either I have to call the phoenix::function real_ or put std::real in
> the operator())
> It seems that the overload get confused. Is there a way to go around this?
> (my poorly written first version --with no phoenix::function-- at
> least didn't have this limitation)

Good point. Well, you can make real_ and friends use the extension
mechanism as before, then use functions for all else.

Duly noted. In phoenix3, we'll have an easy way to have nullary
functions which do not require ().

Thanks for working on this! Very good timing! :-)

Regards,

-- 
Joel de Guzman
http://www.boostpro.com
http://spirit.sf.net

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