Re: Compilation Bug in Quantlib Array
Posted by
Luigi Ballabio-2 on
URL: http://quantlib.414.s1.nabble.com/Date-problem-in-swaptionhelper-cpp-tp2210p2213.html
Hi Bill,
At 11:08 AM -0400 9/28/02, Bill wrote:
> I am experiencing compilation problems with
> Microsoft VC6 on quantlib section Array.h.
> I believe the problem is in the std::ptr_fun it won't run in
> release mode gives strange error messages like not enough
> arguments.
Hmm. Could you send me the error, to see if I can make head or tail of it?
>Since its function is to make abs derive from
> std::unary function the trick is to do it the long way.
> Replace the above code with
>
>
> template <class T1, class T2>
> struct qlfabs : public std::unary_function<T1, T2>
> { T1 operator() (T2 x ) const
> {return ::abs(x) ; }
> };
>
> inline Array Abs(const Array& v) {
> Array result(v.size());
> std::transform(v.begin(),v.end(),result.begin(),
> //std::ptr_fun(QL_FABS));
> qlfabs<double, double>());
> return result;
> }
>
>
> You also have to do this with Sqrt, Log,and Exp.
Well, the purpose of using std::ptr_fun was brevity. If it gives
problems, I guess the next simplest way would be to write
inline Array Abs(const Array& v) {
Array result(v.size());
for (unsigned i=0; i<v.size(); i++)
result[i] = QL_FABS(v[i]);
return result;
}
Thanks for the report,
Luigi