
AMDG alfC wrote:
Ok, I gave up with Boost.Lambda for defining such "lazy function" and used Phoenix instead. The process was quite painless. Below is the (working) code to define a lazy complex modulus function for those who are interested. I have still two concerns though:
1) I am worried how the lazy function can figure out which version of std::norm<T> to call to obtain the right result. For std::complex<double> the lazy function works fine (double is hard coded). But for std::complex<int> it seems that the lazy function will always convert the result to double, I couldn't make the lazy funcion as generic as the original std::norm<T>(std::complex<T> const& c) function. Is it possible to improve the lazy function definition in that respect? (BTW, for std::complex, T == std::complex<T>::value_type)
result is a template, so you just need to specialize it or use some kind of metaprogramming (for instance Boost.Typeof).
(It is not that I think std::complex<int> is useful for something but I thing it is a good example to ask about this).
In fact, according to 26.2 "The effect of instantiating the template complex for any type other than float, double or long double is unspecified."
2) I may be asking for too much sugar but is there a way to name the function "std::norm" and not have conflicts with the standard "std::norm<T>(std::complex<T> const& c)", the best I could do was to call it std::norm_;
You're not allowed to put it in namespace std at all. In Christ, Steven Watanabe