Posted by
Kim Kuen Tang on
URL: http://quantlib.414.s1.nabble.com/Null-class-bug-on-x64-targets-tp9091p9092.html
Hi Kakhkhor,
Kakhkhor Abdijalilov schrieb:
> Null<Size> may not properly compile on x64 targets because. This
> happened to me with Intel C++ compiler.
i tested the original code in quanlib and i 've got the error that no
constructor is provided. But this is due to the fact that the macro x64
is not recognised by the compiler.
In fact there is no such symbol defined by the C++ standard. It depends
on the compiler.
See the following code snippet:
#ifdef x64
//! template class providing a null value for a given type.
template <>
class Null<Size> {
public:
Null() {}
operator Size() const { return Size(QL_NULL_INTEGER); }
};
#endif
If the macro is properly set then the compile error should disappear. In
case of visual stuio it is _M_X64. Perhaps boost has implemented an
universal one.
> Proposal to change the Null
> class with something like this.
>
If you really want to change the class, you should open a ticker and
supply a patch.
But i see the problem that ur code doesnt prevent the user from writing
code like Null<std::vector<double> >().
Kim
> //---------------------------------------------------------------------------
> #include <ql/types.hpp>
> #include <limits>
> #include <boost/type_traits.hpp>
>
> typedef double Real;
>
> template <bool>
> struct IntegerNull {
> static int value() {
> return std::numeric_limits<int>::max();
> }
> };
>
> template <>
> struct IntegerNull<false> {
> static Real value() {
> return std::numeric_limits<Real>::max();
> }
> };
>
> template <typename T>
> class Null {
> public:
> Null() {}
> operator T() const {
> return T(IntegerNull<boost::is_floating_point<T>::value>::value());
> }
> };
> //---------------------------------------------------------------------------
>
> Even better solution would be replace it with boost::optional but I
> guess Null is needed for backward compatibility.
>
> Regards,
> Kakhkhor Abdijalilov.
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by
>
> Make an app they can't live without
> Enter the BlackBerry Developer Challenge
>
http://p.sf.net/sfu/RIM-dev2dev
> _______________________________________________
> QuantLib-dev mailing list
>
[hidden email]
>
https://lists.sourceforge.net/lists/listinfo/quantlib-dev>
>
------------------------------------------------------------------------------
This SF.net email is sponsored by
Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev