
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).
Do you mean that I should do something like (not tested)::
template<class R>
struct norm_impl{
template <typename Arg>
struct result{
typedef R type;
};
template <typename Arg>
typename result<Arg>::type operator()(Arg ar1) const{
return std::norm(ar1);
}
};
template<class R> struct norm{
static(???) phoenix::function
(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."
Good point, thank you. I should have asked for the std::complex<float> instead.
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.
Obviously there is a mapping between standard functions and lazy functions (in Phoenix for example), Is there a way to express this mapping in their names? Thanks, Alfredo