Boost logo

Boost Users :

Subject: Re: [Boost-users] [lambda][phoenix] make lambda/phoenix play well with std::complex, imag, real, abs, etc.
From: Alfredo Correa (correaa_at_[hidden])
Date: 2010-06-07 03:42:07


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)

Thank you,
Alfredo


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