Compilation Bug in Quantlib Array
Posted by Bill Shortall on
URL: http://quantlib.414.s1.nabble.com/Date-problem-in-swaptionhelper-cpp-tp2210p2212.html
Hi Folks,
I am experiencing compilation problems with
Microsoft VC6 on quantlib section Array.h.
It compiles and runs fine in DEBUG mode but
in release mode it generates errors. The
problem is only experienced when running
with expression templates turned off. The bug
seems to be in sections like
inline Array Abs(const Array& v) {
Array result(v.size());
std::transform(v.begin(),v.end(),result.begin(),
std::ptr_fun(QL_FABS));
return result;
}
where QL_FABS is abs the std C function. 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.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.
Regards...Bill