Posted by
Kim Kuen Tang on
URL: http://quantlib.414.s1.nabble.com/Null-class-bug-on-x64-targets-tp9091p9094.html
Kakhkhor Abdijalilov schrieb:
> Null class is rather confusing. We have Null<int>, Null<long>,
> Null<long long>, Null<unsigned long>, Null<unsigned int>, Null<float>,
> Null<double>, Null<long double> etc. Null<Size> is bound to conflict
> with some of those Nulls on 32 bit platforms, that is why a macro
> switch was needed.
Sorry, cant agree with this point. For a 32-bit msvc compiler size_t is
just unsigned int. ( The actual implementation depends on the
compiler.) Since a specialization for the class Null already exists ,
you can write Null<Size>.
A macro switch is needed because for a 64bit msvc compiler size_t is
defined by
typedef unsigned __int64 size_t; (see crtdefs.h, line 488).
And since the class Null is not specialised for this type, u need
explicitly to define one.
> But the same macro brakes Null on 64 bit platforms.
>
Again u just need to set the correct macro, then the error should disappear.
> Boost::optional is much better and already used in QuantLib. We should
> use it instead of Null whenever possible. But working Null is still
> needed for backward compatibility.
>
> Only POD types need Null.
There exist also specializations for Non-POD objects like Array and
IntervalPrice.
Kim
> Null<std::vector<double> > isn't a
> minefield. We can't accidentally do something like this
>
> POD_type x = Null<std::vector<double> >.
>
> It won't compile.
>
>
> Below is the null.hpp I am using with QuantLib. I doesn't depend on
> x64 macro and works on both 32 and 64 bit platforms
> //---------------------------------------------------------------------------------------------
> #ifndef quantlib_null_hpp
> #define quantlib_null_hpp
>
> #include <ql/types.hpp>
> #include <limits>
> #include <boost/type_traits.hpp>
>
> namespace QuantLib {
>
> template <bool>
> struct FloatingPointNull;
>
> // null for floating poit types
> template <>
> struct FloatingPointNull<true> {
> static float nullValue() {
> return std::numeric_limits<float>::max();
> }
> };
>
> // null for integer types
> template <>
> struct FloatingPointNull<false> {
> static int nullValue() {
> return std::numeric_limits<int>::max();
> }
> };
>
> template <typename T>
> class Null {
> public:
> Null() {}
> operator T() const {
> return
> T(FloatingPointNull<boost::is_floating_point<T>::value>::nullValue());
> }
> };
>
> }
>
> #endif
> //---------------------------------------------------------------------------------------------
>
> 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