|
Boost Users : |
Subject: Re: [Boost-users] [lambda] extending lambda functions
From: alfC (alfredo.correa_at_[hidden])
Date: 2009-03-24 11:22:19
> > 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<norm_impl<R> > func;
};
and use norm<double>::func (instead of norm_);
How Boost.TypeOf fits in this or other approach?
> > (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
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